Skip to content
This repository has been archived by the owner on May 16, 2021. It is now read-only.

Commit

Permalink
feat: add a config remover
Browse files Browse the repository at this point in the history
  • Loading branch information
mainawycliffe committed Dec 10, 2019
1 parent 516d60a commit 9e38de6
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions configs/viper.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package configs

import (
"bytes"
"encoding/json"
"fmt"
"strings"

"github.com/spf13/viper"
)

func UnsetViperConfig(keys ...string) error {
configMap := viper.AllSettings()
for _, key := range keys {
delete(configMap, strings.ToLower(key))
}
encodedConfig, err := json.MarshalIndent(configMap, "", " ")
if err != nil {
return err
}
err = viper.ReadConfig(bytes.NewReader(encodedConfig))
if err != nil {
return err
}
err = viper.WriteConfig()
if err != nil {
return fmt.Errorf("Error removing configs: %w", err)
}
return nil
}

0 comments on commit 9e38de6

Please sign in to comment.