Adding -ConfigPath option
This commit is contained in:
parent
87c40eed1a
commit
185008c51e
2 changed files with 12 additions and 5 deletions
|
@ -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:
|
||||
|
|
|
@ -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")
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue