Skip to content

Commit

Permalink
added toml back, updated README
Browse files Browse the repository at this point in the history
fixed kairos-config.toml in gitignore
  • Loading branch information
Rom3dius committed Apr 3, 2024
1 parent df02b60 commit ad79709
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ result
target
.tmp
.nixos-test-history
kairos_config.toml
kairos-config.toml
kairos.log
7 changes: 4 additions & 3 deletions kairos-server/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@

## Configuration

You can configure this application through environment variables, dotenv or a toml file. Below you can see examples of the latter two.
You can configure this application through environment variables, dotenv or a toml file. Below you can see examples of the latter two.

**dotenv**
**.env**
```
KAIROS_SERVER_PORT="8000"
KAIROS_SERVER_ADDRESS="0.0.0.0"
KAIROS_LOG_LEVEL="trace" # trace, debug, info, warn, error
KAIROS_LOG_FILE="kairos.log" # Optional
```

**kairos_config.toml**
**kairos-config.toml**
You can also supply the config's path as a command line argument.
```
[server]
address = "0.0.0.0"
Expand Down
17 changes: 13 additions & 4 deletions kairos-server/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use config::{Config as Configuration, Environment};
use config::{Config as Configuration, Environment, File};
use dotenvy::dotenv;
use serde::{Deserialize, Serialize};
use std::{fs::File as FsFile, net::SocketAddr};
use std::{env, fs::File as FsFile, net::SocketAddr, path::Path};
use tracing::{subscriber::set_global_default, Level};
use tracing_subscriber::{fmt, prelude::*, EnvFilter};

Expand Down Expand Up @@ -62,10 +62,19 @@ impl Settings {
pub fn new() -> Self {
dotenv().ok();

// Start building the configuration
let mut builder = Configuration::builder();

// Add environment variables as a source
let args: Vec<String> = env::args().collect();
let config_path = if args.len() > 1 {
&args[1]
} else {
"kairos-config.toml"
};

if Path::new(config_path).exists() {
builder = builder.add_source(File::new(config_path, config::FileFormat::Toml));
}

builder = builder.add_source(Environment::with_prefix("KAIROS").separator("_"));
match builder.build() {
Ok(config) => match config.try_deserialize::<Self>() {
Expand Down

0 comments on commit ad79709

Please sign in to comment.