I try to create configuration file for my go app what loops through some jobs.
My .yaml file looks like that (array):
jobToRun:
- name: This is my first job to run
sqlToRun: select 1 from some_table
someVariable: 1
- name: Other job to run
sqlToRun: select 2 from some_table
someVariable: 2
I have successfully imported the YAML file and created also structure.
type Service struct {
JobToRun []struct {
Name string `yaml:"name"`
SQLToRun string `yaml:"SqlToRun"`
SomeVariable int `yaml:"someVariable"`
} `yaml:"jobToRun"`
}
But I have no idea how to assign them to variable.
I tried some stuff what work with Json array-s but without any luck.
So I tried to print it to console without any luck:
println(service.JobToRun.name[0])
before that I tried to assign that SQL to my variable (which works if it is not an array item.
var sqlQuery = service.JobToRun.name[0]
And here is what I try to accomplish:
I take the Job parameters from .yaml array and run it.
I am using that kind of array in YAML because it is easiest way to add new jobs.