From 05f4d8173d516ef28c59375ddad96094bd2038dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Denis=20Nu=C8=9Biu?= Date: Fri, 24 Nov 2017 22:37:09 +0200 Subject: [PATCH] refactoring config variable names --- README.md | 8 ++++---- server/server/config.go | 12 ++++++------ server/server/config_test.go | 10 +++++----- server/simplFTP.go | 6 +++--- 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index c69bf0a..bb66083 100644 --- a/README.md +++ b/README.md @@ -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" } ``` diff --git a/server/server/config.go b/server/server/config.go index 5d92029..107f8ab 100644 --- a/server/server/config.go +++ b/server/server/config.go @@ -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() diff --git a/server/server/config_test.go b/server/server/config_test.go index e323243..0479909 100644 --- a/server/server/config_test.go +++ b/server/server/config_test.go @@ -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!") } diff --git a/server/simplFTP.go b/server/simplFTP.go index ebdd806..76e0a4b 100644 --- a/server/simplFTP.go +++ b/server/simplFTP.go @@ -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)