refactoring config variable names
This commit is contained in:
parent
2573be8e2d
commit
05f4d8173d
4 changed files with 18 additions and 18 deletions
|
@ -14,10 +14,10 @@ If no configuration file is provided the server will run with the default settin
|
|||
Sample Configuration File:
|
||||
```
|
||||
{
|
||||
"Address": "localhost",
|
||||
"Port": "8000",
|
||||
"MaxDirDepth": 30,
|
||||
"AbsoluteServePath": "./"
|
||||
"address": "localhost",
|
||||
"port": "8080",
|
||||
"maxDirDepth": 30,
|
||||
"absoluteServePath": "/Users/denis/Dropbox/Pictures/CuteAvatars"
|
||||
}
|
||||
```
|
||||
|
||||
|
|
|
@ -26,16 +26,16 @@ func loadConfigFromFile() error {
|
|||
|
||||
// setDefaultConfiguration will set the default configuration settings.
|
||||
func setDefaultConfiguration() {
|
||||
viper.SetDefault("Address", "localhost")
|
||||
viper.SetDefault("Port", "8080")
|
||||
viper.SetDefault("ConfigPath", ConfigPath)
|
||||
viper.SetDefault("MaxDirDepth", 30)
|
||||
viper.SetDefault("AbsoluteServePath", "./")
|
||||
viper.SetDefault("address", "localhost")
|
||||
viper.SetDefault("port", "8080")
|
||||
viper.SetDefault("configPath", ConfigPath)
|
||||
viper.SetDefault("maxDirDepth", 30)
|
||||
viper.SetDefault("absoluteServePath", "./")
|
||||
}
|
||||
|
||||
// InitializedConfiguration initializes the configuration for the application.
|
||||
func InitializedConfiguration() {
|
||||
flag.StringVar(&ConfigPath, "ConfigPath", ".", "Set the location of the config file.")
|
||||
flag.StringVar(&ConfigPath, "config", ".", "Set the location of the config file.")
|
||||
flag.Parse()
|
||||
|
||||
setDefaultConfiguration()
|
||||
|
|
|
@ -10,27 +10,27 @@ func TestLoadConfigFromFile(t *testing.T) {
|
|||
// SetDefaultConfiguration must be called BEFORE LoadConfigFromFile.
|
||||
InitializedConfiguration()
|
||||
|
||||
Address := viper.GetString("Address")
|
||||
Address := viper.GetString("address")
|
||||
if Address == "" {
|
||||
t.Error("TestLoadConfigFromFile: Can't get Address!")
|
||||
}
|
||||
|
||||
Port := viper.GetString("Port")
|
||||
Port := viper.GetString("port")
|
||||
if Port == "" {
|
||||
t.Error("TestLoadConfigFromFile: Can't get Port!")
|
||||
}
|
||||
|
||||
ConfigPath := viper.GetString("ConfigPath")
|
||||
ConfigPath := viper.GetString("configPath")
|
||||
if ConfigPath == "" {
|
||||
t.Error("TestLoadConfigFromFile: Can't get ConfigPath!")
|
||||
}
|
||||
|
||||
DirDepth := viper.GetInt("MaxDirDepth")
|
||||
DirDepth := viper.GetInt("maxDirDepth")
|
||||
if DirDepth == 0 {
|
||||
t.Error("TestLoadConfigFromFile: Can't get DirDepth!")
|
||||
}
|
||||
|
||||
BasePath := viper.GetString("AbsoluteServePath")
|
||||
BasePath := viper.GetString("absoluteServePath")
|
||||
if BasePath == "" {
|
||||
t.Error("TestLoadConfigFromFile: Can't get AbsoluteServePath!")
|
||||
}
|
||||
|
|
|
@ -11,9 +11,9 @@ import (
|
|||
func main() {
|
||||
server.InitializedConfiguration()
|
||||
|
||||
Addr := viper.GetString("Address")
|
||||
Port := viper.GetString("Port")
|
||||
DirDepth := viper.GetInt("MaxDirDepth")
|
||||
Addr := viper.GetString("address")
|
||||
Port := viper.GetString("port")
|
||||
DirDepth := viper.GetInt("maxDirDepth")
|
||||
|
||||
// Start the server
|
||||
listener, err := net.Listen("tcp", Addr+":"+Port)
|
||||
|
|
Loading…
Reference in a new issue