I’ve multiple yaml files which need to be parsed and have exactly the same structure
schema: "1.0.0"
id: test
version: "1.2.3"
dependency :
- name: ui
type: runner
cwd: /ui
install:
- name: api
group: test
properties:
name: app
url: appUrl
- name: backend
type: mongoDb
path: be
install:
- name: db
type: mongo
provides:
- name: api
properties:
url: url
The schema section is mandatory for all the yaml which the app should get always
The dependency tag can contain 1..n entries with mandatory fields ,name, type, cwd
The dependency tag can (or not) contain
install
section withname
andproperties
which is mandatoryThe dependency tag can (or not) contain
provides
section withname
and which is mandatoryThe install can have properties and the provides also can have properties
I am using a yaml parser to parse the files but my question is how in Golang I can build struct that when I parse the doc it will automatically fill the main struct and will include the sub structs (such as dependency/ install sections )
I have tried something like
type main struct {
schema struct {
schema string
id int
version string
}
dependency struct {
name string
type string
cwd string
install struct {
name string
}
}
In the install section, it can be group or type or both and it can have also properties section, so I'm not sure how to build some generic /extendable struct which I use to parse the document (the document have close list of properties, what I put in the example describe the most options)
I use this lib to parse the doc