Add dpts-config module
This commit is contained in:
parent
c4c5ef0027
commit
b3368076e8
12 changed files with 126 additions and 12 deletions
50
Cargo.lock
generated
50
Cargo.lock
generated
|
@ -774,6 +774,7 @@ checksum = "1aaf95b3e5c8f23aa320147307562d361db0ae0d51242340f558153b4eb2439b"
|
|||
name = "dpts"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"dpts-config",
|
||||
"dpts-csv",
|
||||
"dpts-database",
|
||||
"dpts-entity",
|
||||
|
@ -790,6 +791,17 @@ dependencies = [
|
|||
"dpts",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "dpts-config"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"dpts-entity",
|
||||
"dpts-error",
|
||||
"serde",
|
||||
"tokio",
|
||||
"toml",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "dpts-csv"
|
||||
version = "0.1.0"
|
||||
|
@ -839,6 +851,7 @@ dependencies = [
|
|||
"anyhow",
|
||||
"clap",
|
||||
"thiserror 2.0.12",
|
||||
"toml",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -2499,6 +2512,15 @@ dependencies = [
|
|||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_spanned"
|
||||
version = "0.6.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "87607cb1398ed59d48732e575a4c28a7a8ebf2454b964fe3f224f2afc07909e1"
|
||||
dependencies = [
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_urlencoded"
|
||||
version = "0.7.1"
|
||||
|
@ -3029,23 +3051,47 @@ dependencies = [
|
|||
"tokio",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "toml"
|
||||
version = "0.8.22"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "05ae329d1f08c4d17a59bed7ff5b5a769d062e64a62d34a3261b219e62cd5aae"
|
||||
dependencies = [
|
||||
"serde",
|
||||
"serde_spanned",
|
||||
"toml_datetime",
|
||||
"toml_edit",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "toml_datetime"
|
||||
version = "0.6.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3da5db5a963e24bc68be8b17b6fa82814bb22ee8660f192bb182771d498f09a3"
|
||||
dependencies = [
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "toml_edit"
|
||||
version = "0.22.25"
|
||||
version = "0.22.26"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "10558ed0bd2a1562e630926a2d1f0b98c827da99fabd3fe20920a59642504485"
|
||||
checksum = "310068873db2c5b3e7659d2cc35d21855dbafa50d1ce336397c666e3cb08137e"
|
||||
dependencies = [
|
||||
"indexmap",
|
||||
"serde",
|
||||
"serde_spanned",
|
||||
"toml_datetime",
|
||||
"toml_write",
|
||||
"winnow",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "toml_write"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bfb942dfe1d8e29a7ee7fcbde5bd2b9a25fb89aa70caea2eba3bee836ff41076"
|
||||
|
||||
[[package]]
|
||||
name = "tower"
|
||||
version = "0.5.2"
|
||||
|
|
14
Cargo.toml
14
Cargo.toml
|
@ -6,17 +6,19 @@ license.workspace = true
|
|||
repository.workspace = true
|
||||
|
||||
[dependencies]
|
||||
dpts-csv = { workspace = true }
|
||||
dpts-entity = { workspace = true }
|
||||
dpts-error = { workspace = true }
|
||||
dpts-migration = { workspace = true }
|
||||
dpts-database = { workspace = true }
|
||||
dpts-config.workspace = true
|
||||
dpts-csv.workspace = true
|
||||
dpts-entity.workspace = true
|
||||
dpts-error.workspace = true
|
||||
dpts-migration.workspace = true
|
||||
dpts-database.workspace = true
|
||||
|
||||
[workspace]
|
||||
members = [".", "dpts-*"]
|
||||
|
||||
[workspace.dependencies]
|
||||
dpts = { path = "." }
|
||||
dpts-config = { path = "dpts-config" }
|
||||
dpts-csv = { path = "dpts-csv" }
|
||||
dpts-database = { path = "dpts-database" }
|
||||
dpts-entity = { path = "dpts-entity" }
|
||||
|
@ -26,6 +28,8 @@ chrono = {version = "0.4", features = ["serde"]}
|
|||
clap = "4.5"
|
||||
dotenv = "0.15.0"
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
tokio = "1.44.2"
|
||||
toml = "0.8.22"
|
||||
|
||||
[workspace.package]
|
||||
version = "0.1.0"
|
||||
|
|
18
dpts-config/Cargo.toml
Normal file
18
dpts-config/Cargo.toml
Normal file
|
@ -0,0 +1,18 @@
|
|||
[package]
|
||||
name = "dpts-config"
|
||||
version.workspace = true
|
||||
edition.workspace = true
|
||||
license.workspace = true
|
||||
repository.workspace = true
|
||||
|
||||
[features]
|
||||
default = ["client", "server"]
|
||||
client = []
|
||||
server = []
|
||||
|
||||
[dependencies]
|
||||
dpts-entity.workspace = true
|
||||
dpts-error.workspace = true
|
||||
serde.workspace = true
|
||||
tokio.workspace = true
|
||||
toml.workspace = true
|
0
dpts-config/src/client.rs
Normal file
0
dpts-config/src/client.rs
Normal file
0
dpts-config/src/global.rs
Normal file
0
dpts-config/src/global.rs
Normal file
9
dpts-config/src/lib.rs
Normal file
9
dpts-config/src/lib.rs
Normal file
|
@ -0,0 +1,9 @@
|
|||
mod client;
|
||||
mod global;
|
||||
mod server;
|
||||
mod user;
|
||||
|
||||
pub use server::{
|
||||
ServerConfig,
|
||||
PartialServerConfig,
|
||||
};
|
37
dpts-config/src/server.rs
Normal file
37
dpts-config/src/server.rs
Normal file
|
@ -0,0 +1,37 @@
|
|||
use dpts_error::Error;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct ServerConfig {
|
||||
pub listen_ips: Vec<String>,
|
||||
pub port: u16,
|
||||
pub database_url: String
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
|
||||
pub struct PartialServerConfig {
|
||||
pub listen_ips: Option<Vec<String>>,
|
||||
pub port: Option<u16>,
|
||||
pub database_url: Option<String>,
|
||||
}
|
||||
|
||||
impl PartialServerConfig {
|
||||
/// #Examples
|
||||
/// ```
|
||||
/// use dpts_config::PartialServerConfig;
|
||||
/// let config = PartialServerConfig::try_from_toml(r#"
|
||||
/// listen_ips = ["0.0.0.0"]
|
||||
/// port = 8000
|
||||
/// database_url = "sqlite::memory:"
|
||||
/// "#).unwrap();
|
||||
/// assert_eq!(config.listen_ips, Some(vec!["0.0.0.0".to_string()]));
|
||||
/// assert_eq!(config.port, Some(8000));
|
||||
/// assert_eq!(config.database_url, Some("sqlite::memory:".to_string()));
|
||||
/// ```
|
||||
///
|
||||
pub fn try_from_toml(s: &str) -> Result<Self, Error> {
|
||||
Ok(toml::from_str(s)?)
|
||||
}
|
||||
}
|
||||
|
0
dpts-config/src/user.rs
Normal file
0
dpts-config/src/user.rs
Normal file
|
@ -17,7 +17,7 @@ axum = "0.8"
|
|||
chrono = {workspace = true}
|
||||
dotenv = {workspace = true}
|
||||
log = "0.4.27"
|
||||
tokio = "1.44.2"
|
||||
tokio.workspace = true
|
||||
|
||||
[dependencies.sea-orm]
|
||||
version = "1.1"
|
||||
|
|
|
@ -8,4 +8,5 @@ repository.workspace = true
|
|||
[dependencies]
|
||||
anyhow = "1.0.98"
|
||||
thiserror = "2.0.12"
|
||||
clap = { workspace = true }
|
||||
clap.workspace = true
|
||||
toml.workspace = true
|
||||
|
|
|
@ -6,6 +6,8 @@ pub enum Error {
|
|||
ParseIntError(#[from] std::num::ParseIntError),
|
||||
#[error("IO Error")]
|
||||
IoError(#[from] std::io::Error),
|
||||
#[error("Parse toml error")]
|
||||
TomlDe(#[from] toml::de::Error),
|
||||
}
|
||||
|
||||
impl Error {
|
||||
|
|
|
@ -1,3 +0,0 @@
|
|||
fn main() {
|
||||
println!("Hello, world!");
|
||||
}
|
Loading…
Add table
Reference in a new issue