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