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 gojsonq
import "errors"
// option describes type for providing configuration options to JSONQ
type option struct {
decoder Decoder
separator string
}
// OptionFunc represents a contract for option func, it basically set options to jsonq instance options
type OptionFunc func(*JSONQ) error
// SetDecoder take a custom decoder to decode JSON
// Deprecated - use WithDecoder
func SetDecoder(u Decoder) OptionFunc {
return WithDecoder(u)
}
// SetSeparator set custom separator for traversing child node, default separator is DOT (.)
// Deprecated - use WithSeparator
func SetSeparator(s string) OptionFunc {
return WithSeparator(s)
}
// WithDecoder take a custom decoder to decode JSON
func WithDecoder(u Decoder) OptionFunc {
return func(j *JSONQ) error {
if u == nil {
return errors.New("decoder can not be nil")
}
j.option.decoder = u
return nil
}
}
// WithSeparator set custom separator for traversing child node, default separator is DOT (.)
func WithSeparator(s string) OptionFunc {
return func(j *JSONQ) error {
if s == "" {
return errors.New("separator can not be empty")
}
j.option.separator = s
return nil
}
}
|