refact: removed figment dependency
This commit is contained in:
parent
7220663240
commit
b53646cb64
|
@ -57,15 +57,6 @@ dependencies = [
|
||||||
"syn",
|
"syn",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "atomic"
|
|
||||||
version = "0.5.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "b88d82667eca772c4aa12f0f1348b3ae643424c8876448f3f7bd5787032e234c"
|
|
||||||
dependencies = [
|
|
||||||
"autocfg",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "autocfg"
|
name = "autocfg"
|
||||||
version = "1.1.0"
|
version = "1.1.0"
|
||||||
|
@ -250,20 +241,6 @@ dependencies = [
|
||||||
"instant",
|
"instant",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "figment"
|
|
||||||
version = "0.10.6"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "790b4292c72618abbab50f787a477014fe15634f96291de45672ce46afe122df"
|
|
||||||
dependencies = [
|
|
||||||
"atomic",
|
|
||||||
"pear",
|
|
||||||
"serde",
|
|
||||||
"serde_json",
|
|
||||||
"uncased",
|
|
||||||
"version_check",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "fnv"
|
name = "fnv"
|
||||||
version = "1.0.7"
|
version = "1.0.7"
|
||||||
|
@ -490,12 +467,6 @@ dependencies = [
|
||||||
"hashbrown",
|
"hashbrown",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "inlinable_string"
|
|
||||||
version = "0.1.15"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "c8fae54786f62fb2918dcfae3d568594e50eb9b5c25bf04371af6fe7516452fb"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "instant"
|
name = "instant"
|
||||||
version = "0.1.12"
|
version = "0.1.12"
|
||||||
|
@ -581,7 +552,6 @@ version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"argh",
|
"argh",
|
||||||
"base64",
|
"base64",
|
||||||
"figment",
|
|
||||||
"redis",
|
"redis",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
|
@ -769,29 +739,6 @@ dependencies = [
|
||||||
"windows-sys",
|
"windows-sys",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "pear"
|
|
||||||
version = "0.2.3"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "15e44241c5e4c868e3eaa78b7c1848cadd6344ed4f54d029832d32b415a58702"
|
|
||||||
dependencies = [
|
|
||||||
"inlinable_string",
|
|
||||||
"pear_codegen",
|
|
||||||
"yansi",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "pear_codegen"
|
|
||||||
version = "0.2.3"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "82a5ca643c2303ecb740d506539deba189e16f2754040a42901cd8105d0282d0"
|
|
||||||
dependencies = [
|
|
||||||
"proc-macro2",
|
|
||||||
"proc-macro2-diagnostics",
|
|
||||||
"quote",
|
|
||||||
"syn",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "percent-encoding"
|
name = "percent-encoding"
|
||||||
version = "2.1.0"
|
version = "2.1.0"
|
||||||
|
@ -865,19 +812,6 @@ dependencies = [
|
||||||
"unicode-xid",
|
"unicode-xid",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "proc-macro2-diagnostics"
|
|
||||||
version = "0.9.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "4bf29726d67464d49fa6224a1d07936a8c08bb3fba727c7493f6cf1616fdaada"
|
|
||||||
dependencies = [
|
|
||||||
"proc-macro2",
|
|
||||||
"quote",
|
|
||||||
"syn",
|
|
||||||
"version_check",
|
|
||||||
"yansi",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "quick-error"
|
name = "quick-error"
|
||||||
version = "1.2.3"
|
version = "1.2.3"
|
||||||
|
@ -1363,15 +1297,6 @@ version = "1.15.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "dcf81ac59edc17cc8697ff311e8f5ef2d99fcbd9817b34cec66f90b6c3dfd987"
|
checksum = "dcf81ac59edc17cc8697ff311e8f5ef2d99fcbd9817b34cec66f90b6c3dfd987"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "uncased"
|
|
||||||
version = "0.9.6"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "5baeed7327e25054889b9bd4f975f32e5f4c5d434042d59ab6cd4142c0a76ed0"
|
|
||||||
dependencies = [
|
|
||||||
"version_check",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "unicase"
|
name = "unicase"
|
||||||
version = "2.6.0"
|
version = "2.6.0"
|
||||||
|
@ -1593,9 +1518,3 @@ name = "windows_x86_64_msvc"
|
||||||
version = "0.32.0"
|
version = "0.32.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "504a2476202769977a040c6364301a3f65d0cc9e3fb08600b2bda150a0488316"
|
checksum = "504a2476202769977a040c6364301a3f65d0cc9e3fb08600b2bda150a0488316"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "yansi"
|
|
||||||
version = "0.5.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "09041cd90cf85f7f8b2df60c646f853b7f535ce68f85244eb6731cf89fa498ec"
|
|
||||||
|
|
|
@ -8,7 +8,6 @@ edition = "2021"
|
||||||
[dependencies]
|
[dependencies]
|
||||||
argh = "0.1.7"
|
argh = "0.1.7"
|
||||||
base64 = "0.13.0"
|
base64 = "0.13.0"
|
||||||
figment = { version = "0.10.6", features = ["json", "env"] }
|
|
||||||
redis = { version = "~0.21.5", features = ["tokio-comp"] }
|
redis = { version = "~0.21.5", features = ["tokio-comp"] }
|
||||||
serde = { version = "~1.0.136", features = ["derive"] }
|
serde = { version = "~1.0.136", features = ["derive"] }
|
||||||
serde_json = "1.0.79"
|
serde_json = "1.0.79"
|
||||||
|
|
46
src/main.rs
46
src/main.rs
|
@ -1,5 +1,5 @@
|
||||||
use argh::FromArgs;
|
use argh::FromArgs;
|
||||||
use figment::{providers::Format, Figment};
|
use core::panic;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::{
|
use std::{
|
||||||
collections::BTreeSet, io::BufRead, net::IpAddr, path::PathBuf, str::FromStr, sync::Arc,
|
collections::BTreeSet, io::BufRead, net::IpAddr, path::PathBuf, str::FromStr, sync::Arc,
|
||||||
|
@ -257,11 +257,45 @@ fn shorten(
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn serve() {
|
async fn serve() {
|
||||||
// Read configuration
|
// Read configuration
|
||||||
let config_file = std::env::var("LONK_CONFIG").unwrap_or("lonk.json".to_string());
|
|
||||||
let config: Config = Figment::new()
|
let config: Config = {
|
||||||
.merge(figment::providers::Json::file(&config_file))
|
let config_file_name = std::env::var("LONK_CONFIG").unwrap_or("lonk.json".to_string());
|
||||||
.extract()
|
let config_file = std::fs::File::open(config_file_name.clone()).unwrap_or_else(|err| {
|
||||||
.expect("Could not parse configuration file.");
|
match err.kind() {
|
||||||
|
std::io::ErrorKind::NotFound => {
|
||||||
|
panic!("Configuration file {} does not exist.", config_file_name)
|
||||||
|
}
|
||||||
|
std::io::ErrorKind::PermissionDenied => {
|
||||||
|
panic!("Read permission to {} was denied.", config_file_name)
|
||||||
|
}
|
||||||
|
_ => panic!(
|
||||||
|
"Error when trying to read configuration file {}: {}",
|
||||||
|
config_file_name, err
|
||||||
|
),
|
||||||
|
};
|
||||||
|
});
|
||||||
|
let config_buf = std::io::BufReader::new(config_file);
|
||||||
|
serde_json::from_reader(config_buf).unwrap_or_else(|err| match err.classify() {
|
||||||
|
serde_json::error::Category::Io => panic!("IO error when reading configuration file."),
|
||||||
|
serde_json::error::Category::Syntax => panic!(
|
||||||
|
"Configuration file is syntactically incorrect.
|
||||||
|
See {}:line {}, column {}.",
|
||||||
|
&config_file_name,
|
||||||
|
err.line(),
|
||||||
|
err.column()
|
||||||
|
),
|
||||||
|
serde_json::error::Category::Data => panic!(
|
||||||
|
"Error deserializing configuration file; expected different data type.
|
||||||
|
See {}:line {}, column {}.",
|
||||||
|
&config_file_name,
|
||||||
|
err.line(),
|
||||||
|
err.column()
|
||||||
|
),
|
||||||
|
serde_json::error::Category::Eof => {
|
||||||
|
panic!("Unexpected end of file when reading configuration file.")
|
||||||
|
}
|
||||||
|
})
|
||||||
|
};
|
||||||
|
|
||||||
// Create slug factory
|
// Create slug factory
|
||||||
let slug_factory = Arc::new(SlugFactory::from_rules(config.slug_rules));
|
let slug_factory = Arc::new(SlugFactory::from_rules(config.slug_rules));
|
||||||
|
|
Loading…
Reference in New Issue