mirror of
https://github.com/ivabus/urouter
synced 2024-11-25 01:45:10 +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]
|
[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"
|
||||||
|
|
23
src/main.rs
23
src/main.rs
|
@ -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())
|
||||||
|
|
Loading…
Reference in a new issue