github.com/go-board/x-go@v0.1.2-0.20220610024734-db1323f6cb15/xcodec/xjson/json.go (about) 1 package xjson 2 3 import ( 4 "encoding/json" 5 6 "github.com/go-board/x-go/xcodec" 7 ) 8 9 const Name = "json" 10 11 type jsonc struct{} 12 13 func (jsonc) Name() string { return Name } 14 15 func (jsonc) Marshal(v interface{}) ([]byte, error) { 16 return json.Marshal(v) 17 } 18 19 func (jsonc) Unmarshal(data []byte, v interface{}) error { 20 return json.Unmarshal(data, v) 21 } 22 23 func init() { 24 xcodec.Register(jsonc{}) 25 } 26 27 func Jsonify(v interface{}) string { 28 data, _ := json.Marshal(v) 29 return string(data) 30 }