-
Notifications
You must be signed in to change notification settings - Fork 3
/
json_driver.go
46 lines (36 loc) · 926 Bytes
/
json_driver.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package config
// default json driver(encoder/decoder)
import (
"encoding/json"
)
// JSONAllowComments support write comments on json file.
var JSONAllowComments = true
// JSONDecoder for json decode
var JSONDecoder Decoder = func(data []byte, v interface{}) (err error) {
if JSONAllowComments {
str := StripComments(string(data))
return json.Unmarshal([]byte(str), v)
}
return json.Unmarshal(data, v)
}
// JSONEncoder for json encode
var JSONEncoder Encoder = json.Marshal
// JSONDriver instance fot json
var JSONDriver = &jsonDriver{name: JSON}
// jsonDriver for json format content
type jsonDriver struct {
name string
ClearComments bool
}
// Name of the driver
func (d *jsonDriver) Name() string {
return d.name
}
// GetDecoder for json
func (d *jsonDriver) GetDecoder() Decoder {
return JSONDecoder
}
// GetEncoder for json
func (d *jsonDriver) GetEncoder() Encoder {
return JSONEncoder
}