summaryrefslogtreecommitdiff
path: root/webhook/src/utils.rs
diff options
context:
space:
mode:
authormatthieu <matthieu@developershouse.xyz>2021-09-03 21:59:04 +0400
committermatthieu <matthieu@developershouse.xyz>2021-09-03 21:59:04 +0400
commitd8a2d4ab8216a0ab4d7b0a0c40de474f0a409c5d (patch)
tree835ce308a20c0c01d10ba158e956bffa0e52a228 /webhook/src/utils.rs
parentf2e6047c21b3ee814670b17e5901d12ac52a3508 (diff)
added the base of the webhook receiver
Diffstat (limited to 'webhook/src/utils.rs')
-rw-r--r--webhook/src/utils.rs59
1 files changed, 59 insertions, 0 deletions
diff --git a/webhook/src/utils.rs b/webhook/src/utils.rs
new file mode 100644
index 0000000..b41156b
--- /dev/null
+++ b/webhook/src/utils.rs
@@ -0,0 +1,59 @@
+use std::env;
+
+use config::{Config, ConfigError, Environment, File};
+use log::{info, trace};
+use serde::Deserialize;
+
+/// Executes the required configuration steps for the program,
+/// uncluding build information, Sentry and logging.
+pub fn setup_program (name: &str) {
+ // todo: this may be replaced by a more complete logger
+
+ let build_info_get = build_info();
+
+ trace!("Starting {} version {} v{} built with {} at {}",
+ name,
+ build_info_get.crate_info.name,
+ build_info_get.crate_info.version,
+ build_info_get.compiler,
+ build_info_get.timestamp
+ );
+}
+
+#[derive(Debug, Deserialize, Clone)]
+pub struct Server {
+ pub port: u16,
+ pub address: String,
+}
+
+#[derive(Debug, Deserialize, Clone)]
+pub struct Discord {
+ pub public_key: String,
+ pub client_id: u32,
+}
+
+
+#[derive(Debug, Deserialize, Clone)]
+pub struct Settings {
+ pub server: Server,
+ pub discord: Discord,
+}
+
+impl Settings {
+ pub fn new() -> Result<Self, ConfigError> {
+ let mut default = Config::default();
+ default.merge(File::with_name("config/default"))?;
+ let mode = env::var("ENV").unwrap_or_else(|_| "development".into());
+ info!("Configuration Environment: {}", mode);
+
+ default.merge(File::with_name(&format!("config/{}", mode)).required(false))?;
+ default.merge(File::with_name("config/local").required(false))?;
+ default.merge(Environment::with_prefix("NOVA_GATEWAY"))?;
+
+ println!("Debug mode: {:?}", default.get_bool("debug"));
+
+ let config: Self = default.try_into().unwrap();
+
+ Ok(config)
+ }
+}