github.com/lingyao2333/mo-zero@v1.4.1/core/mapping/tomlunmarshaler.go (about) 1 package mapping 2 3 import ( 4 "bytes" 5 "encoding/json" 6 "io" 7 8 "github.com/pelletier/go-toml/v2" 9 ) 10 11 // UnmarshalTomlBytes unmarshals TOML bytes into the given v. 12 func UnmarshalTomlBytes(content []byte, v interface{}) error { 13 return UnmarshalTomlReader(bytes.NewReader(content), v) 14 } 15 16 // UnmarshalTomlReader unmarshals TOML from the given io.Reader into the given v. 17 func UnmarshalTomlReader(r io.Reader, v interface{}) error { 18 var val interface{} 19 if err := toml.NewDecoder(r).Decode(&val); err != nil { 20 return err 21 } 22 23 var buf bytes.Buffer 24 if err := json.NewEncoder(&buf).Encode(val); err != nil { 25 return err 26 } 27 28 return UnmarshalJsonReader(&buf, v) 29 }