Cleaned up config handling
- moved everything to cmd/root.go - Sanitize all paths to full absolute ones - Set a config key with the current config basedir - moved default config logging to a central location - resolve user config dir relative to config dir - change cwd to config dir
This commit is contained in:
@ -3,6 +3,7 @@ package service
|
||||
import (
|
||||
"encoding/json"
|
||||
"log"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
@ -40,7 +41,12 @@ func LoadConfig() {
|
||||
// viper.UnmarshalKey("Service", &C)
|
||||
C.DNS.Server = viper.GetString("Service.DNS.Server")
|
||||
C.DNS.DefaultTTL = viper.GetUint32("Service.DNS.DefaultTTL")
|
||||
C.Users.ConfigDir = viper.GetString("Service.Users.ConfigDir")
|
||||
path := viper.GetString("Service.Users.ConfigDir")
|
||||
if filepath.IsAbs(path) {
|
||||
C.Users.ConfigDir = filepath.Clean(path)
|
||||
} else {
|
||||
C.Users.ConfigDir = filepath.Join(viper.GetString("ConfigDir"), path)
|
||||
}
|
||||
}
|
||||
|
||||
func (obj *config) PrettyPrint() string {
|
||||
|
Reference in New Issue
Block a user