Code cleanup and missing error checks

This commit is contained in:
Philipp Wolfer 2023-12-10 13:51:38 +01:00
parent 6eaef18188
commit c4193f42a1
No known key found for this signature in database
GPG key ID: 8FDF744D4919943B
7 changed files with 23 additions and 19 deletions

View file

@ -61,7 +61,8 @@ func InitConfig(cfgFile string) error {
// Create global config if it does not exist
if viper.ConfigFileUsed() == "" && cfgFile == "" {
if err := os.MkdirAll(configDir, 0750); err == nil {
viper.SafeWriteConfig()
// This call is expected to return an error if the file already exists
viper.SafeWriteConfig() //nolint:errcheck
}
}
@ -82,7 +83,7 @@ func WriteConfig(removedKeys ...string) error {
configMap := viper.AllSettings()
for _, key := range removedKeys {
c := configMap
ok := true
var ok bool
subKeys := strings.Split(key, ".")
keyLen := len(subKeys)
// Deep search the key in the config and delete the deepest key, if it exists