github.com/annwntech/go-micro/v2@v2.9.5/config/encoder/toml/toml.go (about)

     1  package toml
     2  
     3  import (
     4  	"bytes"
     5  
     6  	"github.com/BurntSushi/toml"
     7  	"github.com/annwntech/go-micro/v2/config/encoder"
     8  )
     9  
    10  type tomlEncoder struct{}
    11  
    12  func (t tomlEncoder) Encode(v interface{}) ([]byte, error) {
    13  	b := bytes.NewBuffer(nil)
    14  	defer b.Reset()
    15  	err := toml.NewEncoder(b).Encode(v)
    16  	if err != nil {
    17  		return nil, err
    18  	}
    19  	return b.Bytes(), nil
    20  }
    21  
    22  func (t tomlEncoder) Decode(d []byte, v interface{}) error {
    23  	return toml.Unmarshal(d, v)
    24  }
    25  
    26  func (t tomlEncoder) String() string {
    27  	return "toml"
    28  }
    29  
    30  func NewEncoder() encoder.Encoder {
    31  	return tomlEncoder{}
    32  }