Apply small fixes and prepare emgauwa-controller
This commit is contained in:
		
							parent
							
								
									bacea1e3e9
								
							
						
					
					
						commit
						d5583e86bc
					
				
					 9 changed files with 150 additions and 6 deletions
				
			
		
							
								
								
									
										24
									
								
								emgauwa-controller/Cargo.toml
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										24
									
								
								emgauwa-controller/Cargo.toml
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,24 @@
 | 
			
		|||
[package]
 | 
			
		||||
name = "emgauwa-controller"
 | 
			
		||||
version = "0.5.0"
 | 
			
		||||
edition = "2021"
 | 
			
		||||
authors = ["Tobias Reisinger <tobias@msrg.cc>"]
 | 
			
		||||
 | 
			
		||||
[dependencies]
 | 
			
		||||
emgauwa-lib = { path = "../emgauwa-lib" }
 | 
			
		||||
 | 
			
		||||
config = "0.13"
 | 
			
		||||
 | 
			
		||||
tokio-tungstenite = "0.20"
 | 
			
		||||
 | 
			
		||||
simple_logger = "4.2"
 | 
			
		||||
log = "0.4"
 | 
			
		||||
 | 
			
		||||
chrono = { version = "0.4", features = ["serde"] }
 | 
			
		||||
uuid = { version = "1.5", features = ["serde", "v4"] }
 | 
			
		||||
 | 
			
		||||
serde = "1.0"
 | 
			
		||||
serde_json = "1.0"
 | 
			
		||||
serde_derive = "1.0"
 | 
			
		||||
 | 
			
		||||
futures = "0.3.29"
 | 
			
		||||
							
								
								
									
										5
									
								
								emgauwa-controller/src/main.rs
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								emgauwa-controller/src/main.rs
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,5 @@
 | 
			
		|||
mod settings;
 | 
			
		||||
 | 
			
		||||
fn main() {
 | 
			
		||||
	let _settings = settings::init();
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										54
									
								
								emgauwa-controller/src/settings.rs
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										54
									
								
								emgauwa-controller/src/settings.rs
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,54 @@
 | 
			
		|||
use config::Config;
 | 
			
		||||
use serde_derive::Deserialize;
 | 
			
		||||
 | 
			
		||||
#[derive(Clone, Debug, Deserialize)]
 | 
			
		||||
#[serde(default)]
 | 
			
		||||
#[allow(unused)]
 | 
			
		||||
pub struct Logging {
 | 
			
		||||
	pub level: String,
 | 
			
		||||
	pub file: String,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[derive(Clone, Debug, Deserialize)]
 | 
			
		||||
#[serde(default)]
 | 
			
		||||
#[allow(unused)]
 | 
			
		||||
pub struct Settings {
 | 
			
		||||
	pub database: String,
 | 
			
		||||
	pub port: u16,
 | 
			
		||||
	pub host: String,
 | 
			
		||||
	pub logging: Logging,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl Default for Settings {
 | 
			
		||||
	fn default() -> Self {
 | 
			
		||||
		Settings {
 | 
			
		||||
			database: String::from("sqlite://emgauwa-controller.sqlite"),
 | 
			
		||||
			port: 5000,
 | 
			
		||||
			host: String::from("127.0.0.1"),
 | 
			
		||||
			logging: Logging::default(),
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl Default for Logging {
 | 
			
		||||
	fn default() -> Self {
 | 
			
		||||
		Logging {
 | 
			
		||||
			level: String::from("info"),
 | 
			
		||||
			file: String::from("stdout"),
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
pub fn init() -> Settings {
 | 
			
		||||
	Config::builder()
 | 
			
		||||
		.add_source(config::File::with_name("emgauwa-controller"))
 | 
			
		||||
		.add_source(
 | 
			
		||||
			config::Environment::with_prefix("EMGAUWA_CONTROLLER")
 | 
			
		||||
				.prefix_separator("_")
 | 
			
		||||
				.separator("__"),
 | 
			
		||||
		)
 | 
			
		||||
		.build()
 | 
			
		||||
		.unwrap()
 | 
			
		||||
		.try_deserialize::<Settings>()
 | 
			
		||||
		.unwrap_or_else(|_| panic!("Error reading settings."))
 | 
			
		||||
}
 | 
			
		||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue