mirror of
https://github.com/NetworkCats/rustyip.git
synced 2026-11-13 16:17:46 +00:00
feat: initialize project with Cargo, config, and dependencies
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
# Server listen address
|
||||
LISTEN_ADDR=0.0.0.0:3000
|
||||
|
||||
# Path to the MaxMind DB file
|
||||
DB_PATH=/data/Merged-IP.mmdb
|
||||
|
||||
# URL to download the MMDB database from
|
||||
DB_UPDATE_URL=https://github.com/NetworkCats/Merged-IP-Data/releases/latest/download/Merged-IP.mmdb
|
||||
|
||||
# How often to check for database updates (in hours)
|
||||
DB_UPDATE_INTERVAL_HOURS=24
|
||||
|
||||
# Site domain name (used for display/metadata)
|
||||
SITE_DOMAIN=localhost
|
||||
@@ -22,5 +22,11 @@ ehthumbs.db
|
||||
ehthumbs_vista.db
|
||||
|
||||
# Project
|
||||
*.mmdb
|
||||
.env
|
||||
haproxy/certs/
|
||||
|
||||
|
||||
# Added by cargo
|
||||
|
||||
/target
|
||||
|
||||
Generated
+1833
File diff suppressed because it is too large
Load Diff
+25
@@ -0,0 +1,25 @@
|
||||
[package]
|
||||
name = "rustyip"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
axum = "0.8.8"
|
||||
tokio = { version = "1.49.0", features = ["full"] }
|
||||
askama = "0.15.4"
|
||||
askama_web = { version = "0.15.1", features = ["axum-0.8"] }
|
||||
maxminddb = "0.27.3"
|
||||
serde = { version = "1", features = ["derive"] }
|
||||
serde_json = "1"
|
||||
arc-swap = "1"
|
||||
reqwest = { version = "0.12", default-features = false, features = ["rustls-tls"] }
|
||||
tracing = "0.1"
|
||||
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
|
||||
tower-http = { version = "0.6", features = ["fs", "set-header"] }
|
||||
|
||||
[profile.release]
|
||||
opt-level = 3
|
||||
lto = true
|
||||
codegen-units = 1
|
||||
strip = true
|
||||
panic = "abort"
|
||||
@@ -0,0 +1,41 @@
|
||||
use std::env;
|
||||
use std::net::SocketAddr;
|
||||
|
||||
pub struct Config {
|
||||
pub listen_addr: SocketAddr,
|
||||
pub db_path: String,
|
||||
pub db_update_url: String,
|
||||
pub db_update_interval_hours: u64,
|
||||
pub site_domain: String,
|
||||
}
|
||||
|
||||
impl Config {
|
||||
pub fn from_env() -> Self {
|
||||
let listen_addr = env::var("LISTEN_ADDR")
|
||||
.unwrap_or_else(|_| "0.0.0.0:3000".to_string())
|
||||
.parse()
|
||||
.expect("LISTEN_ADDR must be a valid socket address");
|
||||
|
||||
let db_path = env::var("DB_PATH").unwrap_or_else(|_| "/data/Merged-IP.mmdb".to_string());
|
||||
|
||||
let db_update_url = env::var("DB_UPDATE_URL").unwrap_or_else(|_| {
|
||||
"https://github.com/NetworkCats/Merged-IP-Data/releases/latest/download/Merged-IP.mmdb"
|
||||
.to_string()
|
||||
});
|
||||
|
||||
let db_update_interval_hours = env::var("DB_UPDATE_INTERVAL_HOURS")
|
||||
.unwrap_or_else(|_| "24".to_string())
|
||||
.parse()
|
||||
.expect("DB_UPDATE_INTERVAL_HOURS must be a valid integer");
|
||||
|
||||
let site_domain = env::var("SITE_DOMAIN").unwrap_or_else(|_| "localhost".to_string());
|
||||
|
||||
Self {
|
||||
listen_addr,
|
||||
db_path,
|
||||
db_update_url,
|
||||
db_update_interval_hours,
|
||||
site_domain,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
mod config;
|
||||
|
||||
fn main() {
|
||||
let _config = config::Config::from_env();
|
||||
}
|
||||
Reference in New Issue
Block a user