From 185008c51e40a197b77676b430233629a8d59f0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Denis=20Nu=C8=9Biu?= Date: Wed, 22 Nov 2017 08:49:16 +0200 Subject: [PATCH] Adding -ConfigPath option --- README.md | 3 ++- server/server/config.go | 14 ++++++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 53b29a4..c69bf0a 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,8 @@ execute commands on it. ## Configuration -The server can be configured via command line flags (soon to come) and a configuration file. +The server can be configured via command line flags with the -ConfigPath option, +specifying a path to the configuration file. If no configuration file is provided the server will run with the default settings. Sample Configuration File: diff --git a/server/server/config.go b/server/server/config.go index 89039b5..6dc0f07 100644 --- a/server/server/config.go +++ b/server/server/config.go @@ -4,9 +4,14 @@ package server import ( "log" + "flag" + "github.com/spf13/viper" ) +// ConfigPath will be used via cmd to set the configuration path for the config file. +var ConfigPath string + // LoadConfig tries to load the configuration file from the disk. func LoadConfigFromFile() error { viper.SetConfigName("config") @@ -23,17 +28,18 @@ func LoadConfigFromFile() error { func SetDefaultConfiguration() { viper.SetDefault("Address", "localhost") viper.SetDefault("Port", "8080") - viper.SetDefault("ConfigPath", ".") + 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.Parse() + SetDefaultConfiguration() + LoadConfigFromFile() - - // TODO, Override from command line flags. - BasePath = viper.GetString("AbsoluteServePath") }