Skip to content

Commit

Permalink
Not sure how to make viper remove items from the toml!
Browse files Browse the repository at this point in the history
This is a workaround for now. I had thought this API correctly removed
items from the toml file, but recent testing shows that it doesn't. The
hack is to write an empty string for the value instead; this works as
long as the client of the config doesn't need to distinguish between no
string and the empty string.
  • Loading branch information
gcla committed Jul 19, 2020
1 parent 69b4335 commit 1e31439
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ func ConfStrings(name string) []string {
func DeleteConf(name string) {
confMutex.Lock()
defer confMutex.Unlock()
delete(viper.Get("main").(map[string]interface{}), name)
viper.Set(name, "")
viper.WriteConfig()
}

Expand Down Expand Up @@ -623,7 +623,7 @@ func SaveOffsetToConfig(name string, offsets2 []resizable.Offset) {
}
}
if len(offsets) == 0 {
DeleteConf(name)
DeleteConf("main." + name)
} else {
offs, err := json.Marshal(offsets)
if err != nil {
Expand Down

0 comments on commit 1e31439

Please sign in to comment.