File tree Expand file tree Collapse file tree 4 files changed +9
-8
lines changed
Expand file tree Collapse file tree 4 files changed +9
-8
lines changed Original file line number Diff line number Diff line change @@ -170,7 +170,7 @@ import (
170170)
171171
172172var dest map [string ]interface {}
173- err := jsonc.CachedDecoder ().Decode (" ./examples/test.json5" , &dest);
173+ err := jsonc.NewCachedDecoder ().Decode (" ./examples/test.json5" , &dest);
174174if err != nil {
175175 fmt.Printf (" %+v " , err)
176176} else {
Original file line number Diff line number Diff line change @@ -8,19 +8,20 @@ import (
88 "strings"
99)
1010
11- type cachedDecoder struct {
11+ // CachedDecoder is a managed decoder that caches a copy of json5 transitioned to json
12+ type CachedDecoder struct {
1213 jsonc * Jsonc
1314 ext string
1415}
1516
16- // CachedDecoder gives a managed decoder that caches a copy of json5 transitioned to json
17- func CachedDecoder (ext ... string ) * cachedDecoder {
17+ // NewCachedDecoder gives a cached decoder
18+ func NewCachedDecoder (ext ... string ) * CachedDecoder {
1819 ext = append (ext , ".cached.json" )
19- return & cachedDecoder {New (), ext [0 ]}
20+ return & CachedDecoder {New (), ext [0 ]}
2021}
2122
2223// Decode decodes from cache if exists and relevant else decodes from source
23- func (fd * cachedDecoder ) Decode (file string , v interface {}) error {
24+ func (fd * CachedDecoder ) Decode (file string , v interface {}) error {
2425 stat , err := os .Stat (file )
2526 if err != nil {
2627 return err
Original file line number Diff line number Diff line change @@ -14,7 +14,7 @@ func main() {
1414 j := jsonc .New ()
1515
1616 // strip and unmarshal from cached file
17- if err := jsonc .CachedDecoder ().Decode ("./examples/test.json5" , & v ); err != nil {
17+ if err := jsonc .NewCachedDecoder ().Decode ("./examples/test.json5" , & v ); err != nil {
1818 fmt .Printf ("%#v\n " , err )
1919 os .Exit (1 )
2020 }
Original file line number Diff line number Diff line change @@ -71,7 +71,7 @@ func TestUnmarshal(t *testing.T) {
7171
7272func TestCachedDecoder (t * testing.T ) {
7373 file := "./examples/test1.json5"
74- cd , val := CachedDecoder (), make (map [string ]interface {})
74+ cd , val := NewCachedDecoder (), make (map [string ]interface {})
7575 t .Run ("before cache" , func (t * testing.T ) {
7676 os .Remove ("./examples/test1.cached.json" )
7777 if err := cd .Decode (file , & val ); err != nil {
You can’t perform that action at this time.
0 commit comments