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:
2021-08-25 21:17:19 +02:00
parent a6e52d9d3d
commit 9952343cda
8 changed files with 58 additions and 45 deletions

View File

@ -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 {