I have this following config file defined as toml file:
[staging]
project-id = "projectId"
cluster-name = "cluster"
zone = "asia-southeast1-a"
Then, I have this struct
type ConfigureOpts struct {
GCPProjectID string `json:"project-id"`
ClusterName string `json:"cluster-name"`
Zone string `json:"zone"`
}
Notice that I have different format of ConfigureOpts fieldname vs the one defined in the config file.
I've tried this code, but failed
test_opts := ConfigureOpts{}
fmt.Printf("viper.staging value %+v\n", viper.GetStringMap("staging"))
viper.UnmarshalKey("staging", &test_opts)
fmt.Printf("testUnmarshall %+v\n", test_opts)
Here is the output
viper.staging value map[zone:asia-southeast1-a project-id:projectId cluster-name:cluster]
testUnmarshall {GCPProjectID: ClusterName: Zone:asia-southeast1-a AuthMode: AuthServiceAccount:}