Debian Codegraph @

parsers/yaml/yaml.go

raw
1 // Package yaml implements a koanf.Parser that parses YAML bytes as conf maps.
2 package yaml
3
4 import (
5 "go.yaml.in/yaml/v3"
6 )
7
8 // YAML implements a YAML parser.
9 type YAML struct{}
10
11 // Parser returns a YAML Parser.
12 func Parser() *YAML {
13 return &YAML{}
14 }
15
16 // Unmarshal parses the given YAML bytes.
17 func (p *YAML) Unmarshal(b []byte) (map[string]any, error) {
18 var out map[string]any
19 if err := yaml.Unmarshal(b, &out); err != nil {
20 return nil, err
21 }
22
23 return out, nil
24 }
25
26 // Marshal marshals the given config map to YAML bytes.
27 func (p *YAML) Marshal(o map[string]any) ([]byte, error) {
28 return yaml.Marshal(o)
29 }