Adding to what @skillian said, a great starting point might be punching your yaml into https://zhwt.github.io/yaml-to-go/, which yields the following:
type AutoGenerated struct {
Version string `yaml:"version"`
Kind string `yaml:"kind"`
Metadata struct {
Name interface{} `yaml:"name"`
VendorID interface{} `yaml:"vendor-id"`
Version interface{} `yaml:"version"`
} `yaml:"metadata"`
Artifacts struct {
Containers []struct {
Name string `yaml:"name"`
Image string `yaml:"image"`
Ports []struct {
Name string `yaml:"name"`
ContainerPort int `yaml:"containerPort"`
} `yaml:"ports"`
VolumeMounts []struct {
MountPath string `yaml:"mountPath"`
Name string `yaml:"name"`
} `yaml:"volumeMounts"`
} `yaml:"containers"`
Bundle []struct {
Name string `yaml:"name"`
Path interface{} `yaml:"path"`
} `yaml:"bundle"`
Web []struct {
Name interface{} `yaml:"name"`
Path interface{} `yaml:"path"`
} `yaml:"web"`
} `yaml:"artifacts"`
}
Using that as a starting point, and hard-coding the yaml:
myYaml := []byte(`version: v1
kind: Extension
metadata:
name:
vendor-id:
version:
artifacts:
containers:
- name: nginx
image: nginx:1.14.2
ports:
- name: http
containerPort: 80
volumeMounts:
- mountPath: /test-ebs
name: http-volume
bundle:
- name: my-bundle
path:
web:
- name:
path:
`)
You could us the library mentioned in your StackOverflow link to unmarshal your yaml and then do whatever checking you want with it:
var myConfig AutoGenerated
err := yaml.Unmarshal(myYaml, &myConfig)
if err != nil {
panic(err)
}
// Do whatever checking you want
fmt.Println(myConfig.Artifacts.Containers[0].Name, "Is a valid config option for container name")
That’s obviously contrived and not very safe. But it should get you started. You can run this example on the playground and edit it to actually satisfy your requirements.