package resource import ( _ "fmt" "io" "gopkg.in/yaml.v3" ) type Document struct { Nodes []yaml.Node `yaml:"resources"` ResourceDecls []Resource `-` } func NewDocument() *Document { return &Document {} } func (d *Document) Load(r io.Reader) error { yamlDecoder := yaml.NewDecoder(r) yamlDecoder.Decode(d) d.ResourceDecls = make([]Resource, len(d.Nodes)) for i,node := range(d.Nodes) { resourceDecl := NewDeclaration() node.Decode(resourceDecl) if r,e := ResourceTypes.New(resourceDecl.Type); e == nil { resourceDecl.Attributes.Decode(r) d.ResourceDecls[i] = r } } return nil } func (d *Document) Resources() []Resource { return d.ResourceDecls }