basic config setup
This commit is contained in:
parent
2b527a325c
commit
8162f81a57
4 changed files with 48 additions and 2 deletions
14
Cargo.lock
generated
14
Cargo.lock
generated
|
@ -1826,6 +1826,8 @@ dependencies = [
|
|||
"smallvec",
|
||||
"sqlformat",
|
||||
"thiserror",
|
||||
"tokio",
|
||||
"tokio-stream",
|
||||
"tracing",
|
||||
"url",
|
||||
]
|
||||
|
@ -1865,6 +1867,7 @@ dependencies = [
|
|||
"sqlx-sqlite",
|
||||
"syn",
|
||||
"tempfile",
|
||||
"tokio",
|
||||
"url",
|
||||
]
|
||||
|
||||
|
@ -2122,6 +2125,17 @@ dependencies = [
|
|||
"windows-sys 0.52.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tokio-stream"
|
||||
version = "0.1.15"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "267ac89e0bec6e691e5813911606935d77c476ff49024f98abcea3e7b15e37af"
|
||||
dependencies = [
|
||||
"futures-core",
|
||||
"pin-project-lite",
|
||||
"tokio",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tokio-util"
|
||||
version = "0.7.13"
|
||||
|
|
|
@ -9,5 +9,5 @@ env_logger = "0.11.5"
|
|||
figment = {version="0.10.19", features=["env"]}
|
||||
log = "0.4.22"
|
||||
serde = {version="1.0.215", features=["derive"]}
|
||||
sqlx = "0.8.2"
|
||||
sqlx = {version="0.8.2", features=["runtime-tokio"]}
|
||||
tokio = "1.42.0"
|
||||
|
|
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
Reference in a new issue