-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rsc: Split configs for rsc/rsc_tool (#1606)
* rsc: Split configs for rsc/rsc_tool * fix tests * further simplify config * fix tests
- Loading branch information
Showing
6 changed files
with
98 additions
and
160 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
use config::{Config, ConfigError, Environment, File}; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
#[derive(Debug, Deserialize, Serialize)] | ||
pub struct RSCConfig { | ||
pub database_url: String, | ||
pub server_addr: String, | ||
pub active_store: String, | ||
} | ||
|
||
impl RSCConfig { | ||
pub fn new() -> Result<RSCConfig, ConfigError> { | ||
// Gather the config | ||
let config = Config::builder() | ||
.add_source(Environment::with_prefix("WAKE_RSC_CONFIG")) | ||
.add_source(File::with_name(".config")) | ||
.build()?; | ||
|
||
config.try_deserialize() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
use config::{Config, ConfigError, Environment, File}; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
#[derive(Debug, Deserialize, Default)] | ||
pub struct RSCToolConfigOverride { | ||
pub database_url: Option<String>, | ||
} | ||
|
||
#[derive(Debug, Deserialize, Serialize)] | ||
pub struct RSCToolConfig { | ||
pub database_url: String, | ||
} | ||
|
||
impl RSCToolConfig { | ||
pub fn new(overrides: RSCToolConfigOverride) -> Result<RSCToolConfig, ConfigError> { | ||
// Gather the config | ||
let config = Config::builder() | ||
.add_source(Environment::with_prefix("WAKE_RSC_CONFIG")) | ||
.add_source(File::with_name(".config").required(false)) | ||
.set_override_option("database_url", overrides.database_url)? | ||
.build()?; | ||
|
||
config.try_deserialize() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
pub mod config; | ||
pub mod database; |