basic config setup
This commit is contained in:
parent
2b527a325c
commit
8162f81a57
4 changed files with 48 additions and 2 deletions
28
src/config.rs
Normal file
28
src/config.rs
Normal file
|
@ -0,0 +1,28 @@
|
|||
use figment::{
|
||||
providers::{Env, Serialized},
|
||||
Figment,
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::net::{IpAddr, Ipv4Addr};
|
||||
|
||||
#[derive(Deserialize, Serialize)]
|
||||
pub struct Config {
|
||||
pub binding_ip: IpAddr,
|
||||
pub port: u16,
|
||||
}
|
||||
|
||||
impl Default for Config {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
binding_ip: IpAddr::V4(Ipv4Addr::LOCALHOST),
|
||||
port: 6767,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn parse_config() -> Config {
|
||||
Figment::from(Serialized::defaults(Config::default()))
|
||||
.merge(Env::prefixed("HILDR"))
|
||||
.extract()
|
||||
.expect("Error parsing config")
|
||||
}
|
|
@ -1,13 +1,17 @@
|
|||
use actix_web::{get, App, HttpServer};
|
||||
use log::info;
|
||||
|
||||
mod config;
|
||||
|
||||
#[actix_web::main]
|
||||
async fn main() -> Result<(), std::io::Error> {
|
||||
env_logger::init();
|
||||
|
||||
let config = config::parse_config();
|
||||
|
||||
info!("Server starting...");
|
||||
HttpServer::new(|| App::new().service(hello))
|
||||
.bind(("127.0.0.1", 6767))?
|
||||
.bind((config.binding_ip, config.port))?
|
||||
.run()
|
||||
.await
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue