2022-05-13 23:17:43 +08:00
|
|
|
package mapping
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io"
|
|
|
|
|
2022-12-08 22:01:36 +08:00
|
|
|
"github.com/zeromicro/go-zero/internal/encoding"
|
2022-05-13 23:17:43 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
// UnmarshalTomlBytes unmarshals TOML bytes into the given v.
|
2023-01-24 16:32:02 +08:00
|
|
|
func UnmarshalTomlBytes(content []byte, v any, opts ...UnmarshalOption) error {
|
2022-12-08 22:01:36 +08:00
|
|
|
b, err := encoding.TomlToJson(content)
|
|
|
|
if err != nil {
|
2022-05-13 23:17:43 +08:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2022-12-08 22:01:36 +08:00
|
|
|
return UnmarshalJsonBytes(b, v, opts...)
|
|
|
|
}
|
|
|
|
|
|
|
|
// UnmarshalTomlReader unmarshals TOML from the given io.Reader into the given v.
|
2023-01-24 16:32:02 +08:00
|
|
|
func UnmarshalTomlReader(r io.Reader, v any, opts ...UnmarshalOption) error {
|
2022-12-08 22:01:36 +08:00
|
|
|
b, err := io.ReadAll(r)
|
|
|
|
if err != nil {
|
2022-05-13 23:17:43 +08:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2022-12-08 22:01:36 +08:00
|
|
|
return UnmarshalTomlBytes(b, v, opts...)
|
2022-05-13 23:17:43 +08:00
|
|
|
}
|