Skip to content

Commit

Permalink
docs: Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
caleb-leinz committed Jul 30, 2024
1 parent 3df74e7 commit 59a6c05
Showing 1 changed file with 55 additions and 1 deletion.
56 changes: 55 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,57 @@
# Freedom Config

Create a Freedom configuration
Utilities for creating an ATLAS Freedom configuration

## Usage

The `freedom-config` API provides an easy to use builder type for constructing
the configuration, which can be invoked with the following:

```rust
use freedom_config::{Config, Test};

fn main() -> Result<(), Box<dyn std::error::Error>> {
let config = Config::builder()
.environment(Test)
.key("my_key")
.secret("my_secret")
.build()?;

println!("{:?}", config);

Ok(())
}
```

The builder can also be used to source these items from the environment:

```rust
use freedom_config::Config;

fn main() -> Result<(), Box<dyn std::error::Error>> {
std::env::set_var(Config::ATLAS_ENV_VAR, "Test");
std::env::set_var(Config::ATLAS_KEY_VAR, "my_key");
std::env::set_var(Config::ATLAS_SECRET_VAR, "my_secret");

let config = Config::builder()
.environment_from_env()?
.key_from_env()?
.secret_from_env()?
.build()?;

println!("{:?}", config);

Ok(())
}
```

Since this is fairly common, there is also a shorthand for constructing the
config entirely from environment variables

```rust
use freedom_config::Config;

fn main() {
let config = Config::from_env();
}
```

0 comments on commit 59a6c05

Please sign in to comment.