Debian Codegraph @

option.go

raw symbols SCIP
1 package gojsonq
2
3 import "errors"
4
5 // option describes type for providing configuration options to JSONQ
6 type option struct {
7 decoder Decoder
8 separator string
9 }
10
11 // OptionFunc represents a contract for option func, it basically set options to jsonq instance options
12 type OptionFunc func(*JSONQ) error
13
14 // SetDecoder take a custom decoder to decode JSON
15 // Deprecated - use WithDecoder
16 func SetDecoder(u Decoder) OptionFunc {
17 return WithDecoder(u)
18 }
19
20 // SetSeparator set custom separator for traversing child node, default separator is DOT (.)
21 // Deprecated - use WithSeparator
22 func SetSeparator(s string) OptionFunc {
23 return WithSeparator(s)
24 }
25
26 // WithDecoder take a custom decoder to decode JSON
27 func WithDecoder(u Decoder) OptionFunc {
28 return func(j *JSONQ) error {
29 if u == nil {
30 return errors.New("decoder can not be nil")
31 }
32 j.option.decoder = u
33 return nil
34 }
35 }
36
37 // WithSeparator set custom separator for traversing child node, default separator is DOT (.)
38 func WithSeparator(s string) OptionFunc {
39 return func(j *JSONQ) error {
40 if s == "" {
41 return errors.New("separator can not be empty")
42 }
43 j.option.separator = s
44 return nil
45 }
46 }