refactoring config variable names

This commit is contained in:
Denis-Cosmin Nutiu 2017-11-24 22:37:09 +02:00
parent 2573be8e2d
commit 05f4d8173d
4 changed files with 18 additions and 18 deletions

View file

@ -14,10 +14,10 @@ If no configuration file is provided the server will run with the default settin
Sample Configuration File: Sample Configuration File:
``` ```
{ {
"Address": "localhost", "address": "localhost",
"Port": "8000", "port": "8080",
"MaxDirDepth": 30, "maxDirDepth": 30,
"AbsoluteServePath": "./" "absoluteServePath": "/Users/denis/Dropbox/Pictures/CuteAvatars"
} }
``` ```

View file

@ -26,16 +26,16 @@ func loadConfigFromFile() error {
// setDefaultConfiguration will set the default configuration settings. // setDefaultConfiguration will set the default configuration settings.
func setDefaultConfiguration() { func setDefaultConfiguration() {
viper.SetDefault("Address", "localhost") viper.SetDefault("address", "localhost")
viper.SetDefault("Port", "8080") viper.SetDefault("port", "8080")
viper.SetDefault("ConfigPath", ConfigPath) viper.SetDefault("configPath", ConfigPath)
viper.SetDefault("MaxDirDepth", 30) viper.SetDefault("maxDirDepth", 30)
viper.SetDefault("AbsoluteServePath", "./") viper.SetDefault("absoluteServePath", "./")
} }
// InitializedConfiguration initializes the configuration for the application. // InitializedConfiguration initializes the configuration for the application.
func InitializedConfiguration() { 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() flag.Parse()
setDefaultConfiguration() setDefaultConfiguration()

View file

@ -10,27 +10,27 @@ func TestLoadConfigFromFile(t *testing.T) {
// SetDefaultConfiguration must be called BEFORE LoadConfigFromFile. // SetDefaultConfiguration must be called BEFORE LoadConfigFromFile.
InitializedConfiguration() InitializedConfiguration()
Address := viper.GetString("Address") Address := viper.GetString("address")
if Address == "" { if Address == "" {
t.Error("TestLoadConfigFromFile: Can't get Address!") t.Error("TestLoadConfigFromFile: Can't get Address!")
} }
Port := viper.GetString("Port") Port := viper.GetString("port")
if Port == "" { if Port == "" {
t.Error("TestLoadConfigFromFile: Can't get Port!") t.Error("TestLoadConfigFromFile: Can't get Port!")
} }
ConfigPath := viper.GetString("ConfigPath") ConfigPath := viper.GetString("configPath")
if ConfigPath == "" { if ConfigPath == "" {
t.Error("TestLoadConfigFromFile: Can't get ConfigPath!") t.Error("TestLoadConfigFromFile: Can't get ConfigPath!")
} }
DirDepth := viper.GetInt("MaxDirDepth") DirDepth := viper.GetInt("maxDirDepth")
if DirDepth == 0 { if DirDepth == 0 {
t.Error("TestLoadConfigFromFile: Can't get DirDepth!") t.Error("TestLoadConfigFromFile: Can't get DirDepth!")
} }
BasePath := viper.GetString("AbsoluteServePath") BasePath := viper.GetString("absoluteServePath")
if BasePath == "" { if BasePath == "" {
t.Error("TestLoadConfigFromFile: Can't get AbsoluteServePath!") t.Error("TestLoadConfigFromFile: Can't get AbsoluteServePath!")
} }

View file

@ -11,9 +11,9 @@ import (
func main() { func main() {
server.InitializedConfiguration() server.InitializedConfiguration()
Addr := viper.GetString("Address") Addr := viper.GetString("address")
Port := viper.GetString("Port") Port := viper.GetString("port")
DirDepth := viper.GetInt("MaxDirDepth") DirDepth := viper.GetInt("maxDirDepth")
// Start the server // Start the server
listener, err := net.Listen("tcp", Addr+":"+Port) listener, err := net.Listen("tcp", Addr+":"+Port)