Print copyright and server message on startup

This commit is contained in:
Luke Harding 2024-05-02 19:33:47 -04:00
parent 95c1cf2930
commit ce121cbf23
4 changed files with 37 additions and 1 deletions

17
server/Cargo.lock generated
View File

@ -328,6 +328,16 @@ version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "colored"
version = "2.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cbf2150cce219b664a8a70df7a1f933836724b503f8a413af9365b4dcc4d90b8"
dependencies = [
"lazy_static",
"windows-sys 0.48.0",
]
[[package]] [[package]]
name = "convert_case" name = "convert_case"
version = "0.4.0" version = "0.4.0"
@ -591,6 +601,12 @@ version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d4345964bb142484797b161f473a503a434de77149dd8c7427788c6e13379388" checksum = "d4345964bb142484797b161f473a503a434de77149dd8c7427788c6e13379388"
[[package]]
name = "lazy_static"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
[[package]] [[package]]
name = "libc" name = "libc"
version = "0.2.154" version = "0.2.154"
@ -724,6 +740,7 @@ name = "personal-tracker-server"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"actix-web", "actix-web",
"colored",
] ]
[[package]] [[package]]

View File

@ -6,3 +6,4 @@ license = "GPL-3.0-only"
[dependencies] [dependencies]
actix-web = "4.5.1" actix-web = "4.5.1"
colored = "2.1.0"

View File

@ -1,9 +1,18 @@
use actix_web::{App, get, HttpResponse, HttpServer, Responder}; use actix_web::{App, get, HttpResponse, HttpServer, Responder};
mod util;
#[actix_web::main] #[actix_web::main]
async fn main() -> std::io::Result<()> { async fn main() -> std::io::Result<()> {
util::print_copyright_notice();
let port = 8000;
let bind_addr = "127.0.0.1";
util::notice_println(format!("Starting server on {}:{}", bind_addr, port));
HttpServer::new(|| App::new().service(hello)) HttpServer::new(|| App::new().service(hello))
.bind(("127.0.0.1", 8000))? .bind((bind_addr, port))?
.run() .run()
.await .await
} }

9
server/src/util.rs Normal file
View File

@ -0,0 +1,9 @@
use colored::Colorize;
pub fn print_copyright_notice() {
println!("{}", "Personal Tracker Server Copyright (C) 2024 Luke Harding <luke@lukeh990.io>\nThis program comes with ABSOLUTELY NO WARRANTY\nThis is free software, and you are welcome to redistribute it under certain conditions\n".italic());
}
pub fn notice_println(msg: impl Into<String>) {
println!("{}", msg.into().green().bold());
}