0.3.5: add option for internal usage

Signed-off-by: Ivan Bushchik <ivabus@ivabus.dev>
This commit is contained in:
Ivan Bushchik 2023-12-20 19:23:54 +03:00
parent 1f3896bb76
commit 4903a4e2e3
No known key found for this signature in database
GPG key ID: 2F16FBF3262E090C
2 changed files with 19 additions and 6 deletions

View file

@ -1,6 +1,6 @@
[package] [package]
name = "urouter" name = "urouter"
version = "0.3.4" version = "0.3.5"
edition = "2021" edition = "2021"
license = "MIT" license = "MIT"
repository = "https://github.com/ivabus/urouter" repository = "https://github.com/ivabus/urouter"

View file

@ -47,6 +47,10 @@ struct Args {
#[arg(long, default_value = "./alias.json")] #[arg(long, default_value = "./alias.json")]
alias_file: PathBuf, alias_file: PathBuf,
/// For internal usage
#[arg(long, default_value = "false")]
alias_file_is_set_not_a_list: bool,
/// Dir to lookup file alias /// Dir to lookup file alias
#[arg(long, default_value = ".")] #[arg(long, default_value = ".")]
dir: PathBuf, dir: PathBuf,
@ -58,6 +62,12 @@ struct Args {
port: u16, port: u16,
} }
// For better compatability with Nix (with set on the top of alias.json instead of a list)
#[derive(Deserialize, Clone, Debug)]
struct NixJson {
alias: Vec<Alias>,
}
#[derive(Deserialize, Clone, Debug)] #[derive(Deserialize, Clone, Debug)]
struct Alias { struct Alias {
uri: String, uri: String,
@ -136,12 +146,15 @@ async fn index(user_agent: UserAgent) -> Response {
#[rocket::main] #[rocket::main]
async fn main() -> Result<(), rocket::Error> { async fn main() -> Result<(), rocket::Error> {
let args = Args::parse(); let args = Args::parse();
let alias: Vec<Alias> = if args.alias_file_is_set_not_a_list {
let set: NixJson =
serde_json::from_str(&smurf::io::read_file_str(&args.alias_file).unwrap()).unwrap();
set.alias
} else {
serde_json::from_str(&smurf::io::read_file_str(&args.alias_file).unwrap()).unwrap()
};
unsafe { unsafe {
ALIAS ALIAS.set(alias).unwrap();
.set(
serde_json::from_str(&smurf::io::read_file_str(&args.alias_file).unwrap()).unwrap(),
)
.unwrap();
} }
let figment = Figment::from(rocket::Config::default()) let figment = Figment::from(rocket::Config::default())