I am reading in a yaml file, and unmarshaling it into a map[interface{}]interface{}
. The goal is to replace a certain value within the yaml, and update the file read in with just that value replaced. I'm not sure how to parse the map though to get to the specific key (password
) I want to change. I believe you can use reflect
, but I'm not 100% sure of the syntax
YAML file I am reading in (config.yml
):
i_name: example
instances:
- name: test-instance
command: get
arguments:
hostname: localhost
port: 203
username: test
password: testing123
labels:
env: dev
Code thus far:
func replaceConfigPassword() {
yamlFile, err := ioutil.ReadFile("config.yml")
fatalIfErr(err)
m := make(map[interface{}]interface{})
err = yaml.Unmarshal(yamlFile, &m)
fatalIfErr(err)
fmt.Println(m)
val := reflect.ValueOf(m["instances"]["arguments"]["password"])
fmt.Println("val=", val)