Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ysuzuki19/enveror-rs
https://github.com/ysuzuki19/enveror-rs
Last synced: 2 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/ysuzuki19/enveror-rs
- Owner: ysuzuki19
- License: mit
- Created: 2023-04-30T13:17:57.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-08-05T15:01:52.000Z (5 months ago)
- Last Synced: 2024-12-17T19:03:08.857Z (10 days ago)
- Language: Rust
- Size: 43.9 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# enveror
[](https://github.com/ysuzuki19/enveror-rs)
[](https://crates.io/crates/enveror)
[](https://docs.rs/enveror)Library for Structured Environment Variables
# Feature
- represent the structure of env-vals using `.`
- define the structure of environment variables using `serde` in `enveror`
- each variable (without object) is fully defined within a single line# Sample
## config
If you want to define following structure,
```json
{
"STAGE": "dev",
"CLOUD": {
"API_KEY_ID": "hogehoge=hog",
"API_SECRET_KEY": "fug+;l[l;uw:er-0-63-096z,nxvcafuga",
"STORAGE": {
"IMAGES": "myimages"
}
},
"CORS_ORIGINS": ["http://localhost:3000", "", "https://enveror.example.com"],
"WORKER_COUNT": 4,
"TIMEOUT_SECONDS": 2.3,
"EMPTY_STRING": " ",
"SAMPLE": true,
"CONFIG": {
"FLAGS": [true, false, false, true],
"NUMBERS": [1, 2, 3, 4, 5, 6, 7, 8, 9]
}
}
```You can set variable as following environment variables.
```
STAGE="dev"
CLOUD.API_KEY_ID="hogehoge=hog"
CLOUD.API_SECRET_KEY="fug+;l[l;uw:er\-0-63-096z,nxvcafuga"
CLOUD.STORAGE.IMAGES="myimages"
CORS_ORIGINS=["http://localhost:3000", "", "https://enveror.example.com"]
WORKER_COUNT=4
TIMEOUT_SECONDS=2.3
EMPTY_STRING=" "
SAMPLE=true
CONFIG.FLAGS=[true, false, false, true]
CONFIG.NUMBERS=[1, 2, 3, 4, 5, 6, 7, 8, 9]
```## code
The following is testing code for parsing and deserialization.
```rust
use std::path::PathBuf;use serde::{Deserialize, Serialize};
#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
enum Stage {
Dev,
Prod,
}#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "UPPERCASE")]
struct EnverorConfig {
stage: Stage,
cloud: Cloud,
cors_origins: Vec,
worker_count: u8,
timeout_seconds: f32,
empty_string: String,
sample: bool,
}#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "UPPERCASE")]
struct Cloud {
api_key_id: String,
api_secret_key: String,
storage: CloudStorage,
}#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "UPPERCASE")]
struct CloudStorage {
images: String,
}extern crate enveror;
#[test]
fn parse_deserialize() -> Result<(), Box> {
enveror::Enveror::new()
.ignore_default_config()
.path(PathBuf::from("./tests/case_enveror"))
.load()?
.construct::()?;
Ok(())
}
```