@@ -48,22 +48,22 @@ fn default_address() -> String {
4848}
4949
5050fn default_port ( ) -> u16 {
51- match Environment :: active ( ) . expect ( "Failed to get current environment" ) {
52- Environment :: Production => 5600 ,
53- Environment :: Development => 5666 ,
54- Environment :: Staging => panic ! ( "Staging environment not supported" ) ,
51+ if is_production ( ) {
52+ 5600
53+ } else {
54+ 5666
5555 }
5656}
5757
5858fn default_cors ( ) -> Vec < String > {
59- match Environment :: active ( ) . expect ( "Failed to get current environment" ) {
60- Environment :: Production => Vec :: < String > :: new ( ) ,
61- Environment :: Development => Vec :: < String > :: new ( ) ,
62- Environment :: Staging => panic ! ( "Staging environment not supported" ) ,
63- }
59+ Vec :: < String > :: new ( )
60+ }
61+
62+ pub fn is_production ( ) -> bool {
63+ ! is_testing ( )
6464}
6565
66- fn is_testing ( ) -> bool {
66+ pub fn is_testing ( ) -> bool {
6767 match Environment :: active ( ) . expect ( "Failed to get current environment" ) {
6868 Environment :: Production => false ,
6969 Environment :: Development => true ,
@@ -73,9 +73,10 @@ fn is_testing() -> bool {
7373
7474pub fn get_config ( ) -> AWConfig {
7575 let mut config_path = dirs:: get_config_dir ( ) . unwrap ( ) ;
76- match is_testing ( ) {
77- false => config_path. push ( "config.toml" ) ,
78- true => config_path. push ( "config-testing.toml" ) ,
76+ if is_production ( ) {
77+ config_path. push ( "config.toml" )
78+ } else {
79+ config_path. push ( "config-testing.toml" )
7980 }
8081
8182 /* If there is no config file, create a new config file with default values but every value is
@@ -98,8 +99,7 @@ pub fn get_config() -> AWConfig {
9899 }
99100
100101 debug ! ( "Reading config at {:?}" , config_path) ;
101- let mut rfile =
102- File :: open ( config_path. clone ( ) ) . expect ( "Failed to open config file for reading" ) ;
102+ let mut rfile = File :: open ( config_path) . expect ( "Failed to open config file for reading" ) ;
103103 let mut content = String :: new ( ) ;
104104 rfile
105105 . read_to_string ( & mut content)
0 commit comments