mirror of
https://github.com/ivabus/urouter
synced 2024-11-22 00:15:11 +03:00
0.3.5: add option for internal usage
Signed-off-by: Ivan Bushchik <ivabus@ivabus.dev>
This commit is contained in:
parent
1f3896bb76
commit
4903a4e2e3
2 changed files with 19 additions and 6 deletions
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "urouter"
|
||||
version = "0.3.4"
|
||||
version = "0.3.5"
|
||||
edition = "2021"
|
||||
license = "MIT"
|
||||
repository = "https://github.com/ivabus/urouter"
|
||||
|
|
23
src/main.rs
23
src/main.rs
|
@ -47,6 +47,10 @@ struct Args {
|
|||
#[arg(long, default_value = "./alias.json")]
|
||||
alias_file: PathBuf,
|
||||
|
||||
/// For internal usage
|
||||
#[arg(long, default_value = "false")]
|
||||
alias_file_is_set_not_a_list: bool,
|
||||
|
||||
/// Dir to lookup file alias
|
||||
#[arg(long, default_value = ".")]
|
||||
dir: PathBuf,
|
||||
|
@ -58,6 +62,12 @@ struct Args {
|
|||
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)]
|
||||
struct Alias {
|
||||
uri: String,
|
||||
|
@ -136,12 +146,15 @@ async fn index(user_agent: UserAgent) -> Response {
|
|||
#[rocket::main]
|
||||
async fn main() -> Result<(), rocket::Error> {
|
||||
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 {
|
||||
ALIAS
|
||||
.set(
|
||||
serde_json::from_str(&smurf::io::read_file_str(&args.alias_file).unwrap()).unwrap(),
|
||||
)
|
||||
.unwrap();
|
||||
ALIAS.set(alias).unwrap();
|
||||
}
|
||||
|
||||
let figment = Figment::from(rocket::Config::default())
|
||||
|
|
Loading…
Reference in a new issue