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