| 1 |
package gojsonq |
| 2 |
|
| 3 |
import "errors" |
| 4 |
|
| 5 |
|
| 6 |
type option struct { |
| 7 |
decoder Decoder |
| 8 |
separator string |
| 9 |
} |
| 10 |
|
| 11 |
|
| 12 |
type OptionFunc func(*JSONQ) error |
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
func SetDecoder(u Decoder) OptionFunc { |
| 17 |
return WithDecoder(u) |
| 18 |
} |
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
func SetSeparator(s string) OptionFunc { |
| 23 |
return WithSeparator(s) |
| 24 |
} |
| 25 |
|
| 26 |
|
| 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 |
|
| 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 |
} |