|
|
|
|
@ -1,7 +1,13 @@
|
|
|
|
|
use std::net::SocketAddr;
|
|
|
|
|
|
|
|
|
|
use serde::Deserialize;
|
|
|
|
|
|
|
|
|
|
#[derive(Deserialize, Debug)]
|
|
|
|
|
pub struct Env {
|
|
|
|
|
#[serde(default = "host_default")]
|
|
|
|
|
pub host: String,
|
|
|
|
|
#[serde(default = "port_default")]
|
|
|
|
|
pub port: String,
|
|
|
|
|
pub mysql_user: String,
|
|
|
|
|
pub mysql_password: String,
|
|
|
|
|
pub mysql_host: String,
|
|
|
|
|
@ -31,6 +37,14 @@ pub struct Env {
|
|
|
|
|
pub get_amf_transaction_interval: u64,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn host_default() -> String {
|
|
|
|
|
"127.0.0.1".to_string()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn port_default() -> String {
|
|
|
|
|
"8000".to_string()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn mysql_port_default() -> String {
|
|
|
|
|
"3306".to_string()
|
|
|
|
|
}
|
|
|
|
|
@ -92,6 +106,7 @@ impl Env {
|
|
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
|
pub struct Config {
|
|
|
|
|
pub server_address: SocketAddr,
|
|
|
|
|
pub database_url: String,
|
|
|
|
|
pub max_connections: u32,
|
|
|
|
|
pub min_connections: u32,
|
|
|
|
|
@ -113,7 +128,12 @@ impl Config {
|
|
|
|
|
env.mysql_user, env.mysql_password, env.mysql_host, env.mysql_port, env.mysql_database
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
let server_address = format!("{}:{}", env.host, env.port)
|
|
|
|
|
.parse()
|
|
|
|
|
.expect("Could not parse host and port combination into a valid server address");
|
|
|
|
|
|
|
|
|
|
let mut config = Config {
|
|
|
|
|
server_address,
|
|
|
|
|
database_url,
|
|
|
|
|
max_connections: env.max_connections,
|
|
|
|
|
min_connections: env.min_connections,
|
|
|
|
|
|