2019-05-31 01:11:13 +03:00
|
|
|
package json
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
|
2020-07-27 15:22:00 +03:00
|
|
|
"github.com/micro/go-micro/v3/config/encoder"
|
2019-05-31 01:11:13 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
type jsonEncoder struct{}
|
|
|
|
|
|
|
|
func (j jsonEncoder) Encode(v interface{}) ([]byte, error) {
|
|
|
|
return json.Marshal(v)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (j jsonEncoder) Decode(d []byte, v interface{}) error {
|
|
|
|
return json.Unmarshal(d, v)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (j jsonEncoder) String() string {
|
|
|
|
return "json"
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewEncoder() encoder.Encoder {
|
|
|
|
return jsonEncoder{}
|
|
|
|
}
|