I wanted to know if this logic is possible in Golang. I have a yaml file as such:
initSteps:
- "pip install --upgrade pip"
- "python3 --version"
buildSteps:
- "pip install ."
runProcess:
- "python3 test.py"
And am using gopkg.in/yaml.v3 to iterate over the steps. I have a function below that puts the instructions into a map like this:
func init() {
// add map from yaml to steps
f, err := ioutil.ReadFile(devrun)
if err != nil {
panic(err)
}
steps = make(map[interface{}]interface{})
err2 := yaml.Unmarshal(f, &steps)
if err2 != nil {
panic(err2)
}
}
And in my main function have this to iterate over the values if the key matches:
for k, v := range steps {
if k == "initSteps" {
s := reflect.ValueOf(v)
for i := 0; i < s.Len(); i++ {
singleVertex := s.Index(i).Elem()
fmt.Println(singleVertex)
}
}
}
I wanted to see if it was possible to iterate over the key from steps though and how I would go about adding this in. This way I can if k.initSteps: The keys from the yaml file will always be the same with the only thing changing being the steps under them.