Debian Codegraph @

parsers/toml/toml.go

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