Codebase list golang-github-spf13-viper / 1862663
feat(encoding): Add json codec Signed-off-by: Mark Sagi-Kazar <mark.sagikazar@gmail.com> Mark Sagi-Kazar authored 3 years ago Márk Sági-Kazár committed 2 years ago
1 changed file(s) with 17 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
0 package json
1
2 import (
3 "encoding/json"
4 )
5
6 // Codec implements the encoding.Encoder and encoding.Decoder interfaces for JSON encoding.
7 type Codec struct{}
8
9 func (Codec) Encode(v interface{}) ([]byte, error) {
10 // TODO: expose prefix and indent in the Codec as setting?
11 return json.MarshalIndent(v, "", " ")
12 }
13
14 func (Codec) Decode(b []byte, v interface{}) error {
15 return json.Unmarshal(b, v)
16 }