@@ -12,8 +12,8 @@ use crate::cli::Cli;
1212
1313#[ derive( Debug , Clone , Deserialize ) ]
1414pub struct Config {
15- pub listen_addr : String , // TODO tokio_listener::ListenerAddressLFlag
16- pub metrics_listen_addr : String , // TODO tokio_listener::ListenerAddressLFlag
15+ pub listen_addr : String , // TODO tokio_listener::ListenerAddressLFlag
16+ pub metrics_listen_addr : Option < String > , // TODO tokio_listener::ListenerAddressLFlag
1717 pub timeout : Duration ,
1818 pub storage_dir : PathBuf ,
1919 pub ohttp_keys : PathBuf , // TODO OhttpConfig struct with rotation params, etc
@@ -31,7 +31,7 @@ impl Config {
3131
3232 Ok ( Config {
3333 listen_addr : built_config. get ( "listen_addr" ) ?,
34- metrics_listen_addr : built_config. get ( "metrics_listen_addr" ) ? ,
34+ metrics_listen_addr : built_config. get ( "metrics_listen_addr" ) . ok ( ) ,
3535 timeout : Duration :: from_secs ( built_config. get ( "timeout" ) ?) ,
3636 storage_dir : built_config. get ( "storage_dir" ) ?,
3737 ohttp_keys : built_config. get ( "ohttp_keys" ) ?,
@@ -41,12 +41,22 @@ impl Config {
4141
4242fn add_defaults ( config : Builder , cli : & Cli ) -> Result < Builder , ConfigError > {
4343 config
44- . set_override_option ( "listen_addr" , Some ( format ! ( "[::]:{}" , cli. port) ) ) ?
44+ . set_default ( "listen_addr" , "[::]:8080" ) ?
45+ . set_override_option ( "listen_addr" , cli. port . map ( |port| format ! ( "[::]:{}" , port) ) ) ?
46+ . set_default ( "metrics_listen_addr" , Option :: < String > :: None ) ?
4547 . set_override_option (
4648 "metrics_listen_addr" ,
47- Some ( format ! ( "localhost:{}" , cli . metrics_port ) ) ,
49+ cli . metrics_port . map ( |port| format ! ( "localhost:{}" , port ) ) ,
4850 ) ?
49- . set_override_option ( "timeout" , Some ( cli. timeout ) ) ?
50- . set_override_option ( "ohttp_keys" , Some ( cli. ohttp_keys . to_string_lossy ( ) . into_owned ( ) ) ) ?
51- . set_override_option ( "storage_dir" , Some ( cli. storage_dir . to_string_lossy ( ) . into_owned ( ) ) )
51+ . set_default ( "timeout" , Some ( 30 ) ) ?
52+ . set_override_option ( "timeout" , cli. timeout ) ?
53+ . set_default ( "ohttp_keys" , "ohttp_keys" ) ?
54+ . set_override_option (
55+ "ohttp_keys" ,
56+ cli. ohttp_keys . clone ( ) . map ( |s| s. to_string_lossy ( ) . into_owned ( ) ) ,
57+ ) ?
58+ . set_override_option (
59+ "storage_dir" ,
60+ cli. storage_dir . clone ( ) . map ( |s| s. to_string_lossy ( ) . into_owned ( ) ) ,
61+ )
5262}
0 commit comments