add port on config

This commit is contained in:
Mylloon 2023-02-08 20:58:24 +01:00
parent 49fcf39612
commit 691c766312
Signed by: Anri
GPG key ID: A82D63DFF8D1317F
2 changed files with 4 additions and 1 deletions

View file

@ -3,6 +3,7 @@ use serde::Deserialize;
#[derive(Deserialize)] #[derive(Deserialize)]
pub struct Config { pub struct Config {
pub scheme: String, pub scheme: String,
pub port: u16,
} }
pub fn get_config(file_path: &str) -> Config { pub fn get_config(file_path: &str) -> Config {
@ -18,6 +19,7 @@ pub fn get_config(file_path: &str) -> Config {
{ {
Config { Config {
scheme: "http".to_string(), scheme: "http".to_string(),
port: 8080,
} }
} }
} }

View file

@ -9,8 +9,9 @@ mod index;
async fn main() -> std::io::Result<()> { async fn main() -> std::io::Result<()> {
let config = config::get_config("config/config.toml"); let config = config::get_config("config/config.toml");
let addr = ("127.0.0.1", 8080); let addr = ("127.0.0.1", config.port);
println!("Listening to {}://{}:{}", config.scheme, addr.0, addr.1); println!("Listening to {}://{}:{}", config.scheme, addr.0, addr.1);
HttpServer::new(|| App::new().service(index::page)) HttpServer::new(|| App::new().service(index::page))
.bind(addr)? .bind(addr)?
.run() .run()