I am using viper for my config. How do I replace a key without replacing the entire map?
package main
import (
"log"
"github.com/spf13/viper"
)
type person struct {
First string
Last string
}
func main() {
v := viper.New()
v.SetEnvPrefix("mememe")
v.AutomaticEnv()
bob := person{
First: "Bob",
Last: "Smith",
}
john := person{
First: "John",
Last: "Boothe",
}
v.SetDefault("people.bob", bob)
v.SetDefault("people.john", john)
log.Println(v.Get("people")) // map[bob:{Bob Smith} john:{John Boothe}]
bob.Last = "Hope"
v.Set("people.bob", bob)
log.Println(v.Get("people")) // map[bob:{Bob Hope}]
}
Upon setting the new Bob I lose John completely. If I change "SetDefault" to simply "Set" then it seems to work but I am wondering why "SetDefault" doesn't work.