json.*JSON.Marshal   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 2
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nop 1
dl 0
loc 2
rs 10
c 0
b 0
f 0
1
package json
2
3
import "encoding/json"
4
5
type Helper interface {
6
	Marshal(v interface{}) ([]byte, error)
7
	Unmarshal(data []byte, v interface{}) error
8
}
9
10
type JSON struct {
11
	json Helper
12
}
13
14
func NewJSON(json Helper) *JSON {
15
	return &JSON{json: json}
16
}
17
18
func (j *JSON) Marshal(v interface{}) ([]byte, error) {
19
	return j.json.Marshal(v)
20
}
21
22
func (j *JSON) Unmarshal(data []byte, v interface{}) error {
23
	return j.json.Unmarshal(data, v)
24
}
25
26
type NativeJSON struct{}
27
28
func (n *NativeJSON) Marshal(v interface{}) ([]byte, error) {
29
	return json.Marshal(v)
30
}
31
32
func (n *NativeJSON) Unmarshal(data []byte, v interface{}) error {
33
	return json.Unmarshal(data, v)
34
}
35