mirror of https://github.com/goccy/go-json.git
Add DecodeOption
This commit is contained in:
parent
e7b7118f4e
commit
f0b4077914
|
@ -24,7 +24,7 @@ type emptyInterface struct {
|
|||
ptr unsafe.Pointer
|
||||
}
|
||||
|
||||
func unmarshal(data []byte, v interface{}) error {
|
||||
func unmarshal(data []byte, v interface{}, optFuncs ...DecodeOptionFunc) error {
|
||||
src := make([]byte, len(data)+1) // append nul byte to the end
|
||||
copy(src, data)
|
||||
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
package decoder
|
||||
|
||||
type Option struct {
|
||||
FirstWin bool
|
||||
}
|
4
json.go
4
json.go
|
@ -258,6 +258,10 @@ func Unmarshal(data []byte, v interface{}) error {
|
|||
return unmarshal(data, v)
|
||||
}
|
||||
|
||||
func UnmarshalWithOption(data []byte, v interface{}, optFuncs ...DecodeOptionFunc) error {
|
||||
return unmarshal(data, v, optFuncs...)
|
||||
}
|
||||
|
||||
func UnmarshalNoEscape(data []byte, v interface{}) error {
|
||||
return unmarshalNoEscape(data, v)
|
||||
}
|
||||
|
|
11
option.go
11
option.go
|
@ -1,11 +1,11 @@
|
|||
package json
|
||||
|
||||
import (
|
||||
"github.com/goccy/go-json/internal/decoder"
|
||||
"github.com/goccy/go-json/internal/encoder"
|
||||
)
|
||||
|
||||
type EncodeOption = encoder.Option
|
||||
|
||||
type EncodeOptionFunc func(*EncodeOption)
|
||||
|
||||
func UnorderedMap() EncodeOptionFunc {
|
||||
|
@ -26,3 +26,12 @@ func Colorize(scheme *ColorScheme) EncodeOptionFunc {
|
|||
opt.ColorScheme = scheme
|
||||
}
|
||||
}
|
||||
|
||||
type DecodeOption = decoder.Option
|
||||
type DecodeOptionFunc func(*DecodeOption)
|
||||
|
||||
func DecodeFieldPriorityFirstWin() DecodeOptionFunc {
|
||||
return func(opt *DecodeOption) {
|
||||
opt.FirstWin = true
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue