Last active
November 1, 2019 17:54
-
-
Save ianfoo/c6cac36cd6892bb6ef81c25e8eeca1e6 to your computer and use it in GitHub Desktop.
Deleting a setting in Viper
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| "bobjects" = { | |
| "limit" = 100 | |
| } | |
| "foo" = { | |
| "blatz" = "quux" | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| "bobjects" = { | |
| "limit" = 100 | |
| } | |
| "foo" = { | |
| "bar" = "baz" | |
| "blatz" = "quux" | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import ( | |
| "os" | |
| "path/filepath" | |
| "github.com/spf13/viper" | |
| ) | |
| func main() { | |
| viper.SetConfigFile(filepath.Join(os.TempDir(), "config.hcl")) | |
| viper.Set("foo.bar", "baz") | |
| viper.Set("foo.blatz", "quux") | |
| viper.Set("bobjects.limit", 100) | |
| viper.WriteConfig() | |
| viper.SetConfigFile(filepath.Join(os.TempDir(), "config-del.hcl")) | |
| viper.Set("foo.bar", nil) | |
| viper.WriteConfig() | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment