package mapping import ( "bytes" "encoding/json" "github.com/pelletier/go-toml/v2" "io" ) // UnmarshalTomlBytes unmarshals TOML bytes into the given v. func UnmarshalTomlBytes(content []byte, v any, opts ...UnmarshalOption) error { b, err := TomlToJson(content) if err != nil { return err } return UnmarshalJsonBytes(b, v, opts...) } // UnmarshalTomlReader unmarshals TOML from the given io.Reader into the given v. func UnmarshalTomlReader(r io.Reader, v any, opts ...UnmarshalOption) error { b, err := io.ReadAll(r) if err != nil { return err } return UnmarshalTomlBytes(b, v, opts...) } func TomlToJson(data []byte) ([]byte, error) { var val any if err := toml.NewDecoder(bytes.NewReader(data)).Decode(&val); err != nil { return nil, err } var buf bytes.Buffer if err := json.NewEncoder(&buf).Encode(val); err != nil { return nil, err } return buf.Bytes(), nil }