Skip to content

Instantly share code, notes, and snippets.

@ianfoo
Last active November 1, 2019 17:54
Show Gist options
  • Select an option

  • Save ianfoo/c6cac36cd6892bb6ef81c25e8eeca1e6 to your computer and use it in GitHub Desktop.

Select an option

Save ianfoo/c6cac36cd6892bb6ef81c25e8eeca1e6 to your computer and use it in GitHub Desktop.
Deleting a setting in Viper
"bobjects" = {
"limit" = 100
}
"foo" = {
"blatz" = "quux"
}
"bobjects" = {
"limit" = 100
}
"foo" = {
"bar" = "baz"
"blatz" = "quux"
}
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