about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authoryuzu <yuzu@b9215c17-b818-4693-b096-d1e41a411fef>2025-07-09 05:14:23 +0000
committeryuzu <yuzu@b9215c17-b818-4693-b096-d1e41a411fef>2025-07-09 05:14:23 +0000
commitdb05108dfaa14044c187d45fc6c9fc479d82b6d0 (patch)
tree2ccad58bbc121f532d30da5df742daef45b34cc5
parentb951ba96d7d985941af8f6e5d413bf8b3d65cf44 (diff)
downloadsalaryman-db05108dfaa14044c187d45fc6c9fc479d82b6d0.tar.gz
salaryman-db05108dfaa14044c187d45fc6c9fc479d82b6d0.tar.bz2
salaryman-db05108dfaa14044c187d45fc6c9fc479d82b6d0.zip
reorganize
git-svn-id: svn+ssh://diminuette.aengel.lesbianunix.dev/salaryman/trunk@11 b9215c17-b818-4693-b096-d1e41a411fef
-rw-r--r--Cargo.toml18
-rw-r--r--src/lib.rs2
-rw-r--r--src/service.rs (renamed from src/model.rs)0
-rw-r--r--src/smd/endpoints.rs1
-rw-r--r--src/smd/main.rs (renamed from src/bin/smd.rs)19
5 files changed, 28 insertions, 12 deletions
diff --git a/Cargo.toml b/Cargo.toml
index 7518b99..703d37f 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -5,14 +5,26 @@ edition = "2024"
 authors = ["Ren Kararou <[email protected]>"]
 description = "A very simple service management framework"
 
+[features]
+default = ["smd"]
+smd = ["dep:clap", "dep:toml"]
+
 [dependencies]
-clap = { version = "4.5.39", features = ["derive"] }
+clap = { version = "4.5.39", features = ["derive"], optional = true }
 serde = { version = "1.0.219", features = ["derive"] }
 tokio = { version = "1.45.1", features = ["full"] }
-toml = "0.8.22"
+toml = { version = "0.8.22", optional = true }
 
 [[bin]]
 name = "smd"
-path = "src/bin/smd.rs"
+path = "src/smd/main.rs"
 test = false
 bench = false
+required-features = ["smd"]
+
+[profile.release]
+strip = true
+lto = "thin"
+panic = "abort"
+codegen-units = 1
+
diff --git a/src/lib.rs b/src/lib.rs
index 65880be..1f278a4 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1 +1 @@
-pub mod model;
+pub mod service;
diff --git a/src/model.rs b/src/service.rs
index 60960e3..60960e3 100644
--- a/src/model.rs
+++ b/src/service.rs
diff --git a/src/smd/endpoints.rs b/src/smd/endpoints.rs
new file mode 100644
index 0000000..8b13789
--- /dev/null
+++ b/src/smd/endpoints.rs
@@ -0,0 +1 @@
+
diff --git a/src/bin/smd.rs b/src/smd/main.rs
index 5a8401a..231701b 100644
--- a/src/bin/smd.rs
+++ b/src/smd/main.rs
@@ -1,12 +1,12 @@
+mod endpoints;
+
 use clap::Parser;
 use serde::{Deserialize, Serialize};
-
 use tokio::fs::read_to_string;
+use salaryman::service::{Service, ServiceConf};
 
 use std::{net::IpAddr, path::PathBuf};
 
-use salaryman::model::{Service, ServiceConf};
-
 #[derive(Parser, Debug)]
 #[command(version, about, long_about = None)]
 struct Args {
@@ -42,6 +42,7 @@ struct Config {
     port: Option<u16>,
     service: Vec<ServiceConf>,
 }
+/*
 impl Config {
     fn new() -> Self {
         Self {
@@ -51,22 +52,23 @@ impl Config {
         }
     }
 }
+*/
 
-async fn load_config(file: &PathBuf) -> Config {
+async fn load_config(file: &PathBuf) -> Result<Config, Box<dyn std::error::Error>> {
     let s: String = match read_to_string(file).await {
         Ok(s) => s,
-        Err(_) => String::new(),
+        Err(_) => return Err(Box::new(std::io::Error::new(std::io::ErrorKind::NotFound, "cannot find config file"))),
     };
     match toml::from_str(s.as_str()) {
-        Ok(c) => c,
-        Err(_) => Config::new(),
+        Ok(c) => Ok(c),
+        Err(_) => Err(Box::new(std::io::Error::new(std::io::ErrorKind::Other, "unable to parse config file"))),
     }
 }
 
 #[tokio::main]
 async fn main() -> Result<(), Box<dyn std::error::Error>> {
     let args = Args::parse();
-    let conf: Config = load_config(&args.config).await;
+    let conf: Config = load_config(&args.config).await?;
     let mut services: Vec<Service> = Vec::new();
     for i in 0..conf.service.len() {
         services.push(Service::from_conf(&conf.service[i]));
@@ -90,3 +92,4 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
     }
     Ok(())
 }
+