pkg/json/json.go   A
last analyzed

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 18
dl 0
loc 41
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A json.*NativeJSON.Marshal 0 2 1
A json.*JSON.Unmarshal 0 2 1
A json.*NativeJSON.Unmarshal 0 2 1
A json.NewJSON 0 2 1
A json.*JSON.Marshal 0 2 1
1
package json
2
3
import "encoding/json"
4
5
// Helper is an interface for JSON helper.
6
type Helper interface {
7
	Marshal(v interface{}) ([]byte, error)
8
	Unmarshal(data []byte, v interface{}) error
9
}
10
11
// JSON is a wrapper for JSON helper.
12
type JSON struct {
13
	json Helper
14
}
15
16
// NewJSON returns a new JSON.
17
func NewJSON(json Helper) *JSON {
18
	return &JSON{json: json}
19
}
20
21
// Marshal marshals the given value to JSON.
22
func (j *JSON) Marshal(v interface{}) ([]byte, error) {
23
	return j.json.Marshal(v)
24
}
25
26
// Unmarshal unmarshals the given JSON to the given value.
27
func (j *JSON) Unmarshal(data []byte, v interface{}) error {
28
	return j.json.Unmarshal(data, v)
29
}
30
31
// NativeJSON is a wrapper for encoding/json.
32
type NativeJSON struct{}
33
34
// Marshal marshals the given value to JSON.
35
func (*NativeJSON) Marshal(v interface{}) ([]byte, error) {
36
	return json.Marshal(v)
37
}
38
39
// Unmarshal unmarshals the given JSON to the given value.
40
func (*NativeJSON) Unmarshal(data []byte, v interface{}) error {
41
	return json.Unmarshal(data, v)
42
}
43