2019-05-31 01:11:13 +03:00
|
|
|
package toml
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
|
|
|
|
"github.com/BurntSushi/toml"
|
2020-08-19 17:47:17 +03:00
|
|
|
"github.com/unistack-org/micro/v3/config/encoder"
|
2019-05-31 01:11:13 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
type tomlEncoder struct{}
|
|
|
|
|
|
|
|
func (t tomlEncoder) Encode(v interface{}) ([]byte, error) {
|
|
|
|
b := bytes.NewBuffer(nil)
|
|
|
|
defer b.Reset()
|
|
|
|
err := toml.NewEncoder(b).Encode(v)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return b.Bytes(), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t tomlEncoder) Decode(d []byte, v interface{}) error {
|
|
|
|
return toml.Unmarshal(d, v)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t tomlEncoder) String() string {
|
|
|
|
return "toml"
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewEncoder() encoder.Encoder {
|
|
|
|
return tomlEncoder{}
|
|
|
|
}
|