diff options
author | 2021-09-10 14:42:14 +0200 | |
---|---|---|
committer | 2021-09-10 14:42:14 +0200 | |
commit | f2e5bedea6fb93fbbf68ed8f7153c353cc57a9f0 (patch) | |
tree | 475ae9e7470d0df670ab2a59dce351cd1d07498a /vendor/github.com/goccy/go-json/option.go | |
parent | fixes + db changes (#204) (diff) | |
download | gotosocial-f2e5bedea6fb93fbbf68ed8f7153c353cc57a9f0.tar.xz |
migrate go version to 1.17 (#203)
* migrate go version to 1.17
* update contributing
Diffstat (limited to 'vendor/github.com/goccy/go-json/option.go')
-rw-r--r-- | vendor/github.com/goccy/go-json/option.go | 45 |
1 files changed, 38 insertions, 7 deletions
diff --git a/vendor/github.com/goccy/go-json/option.go b/vendor/github.com/goccy/go-json/option.go index 6837a4b1b..ad6509183 100644 --- a/vendor/github.com/goccy/go-json/option.go +++ b/vendor/github.com/goccy/go-json/option.go @@ -1,15 +1,46 @@ package json -type EncodeOptionFunc func(EncodeOption) EncodeOption +import ( + "github.com/goccy/go-json/internal/decoder" + "github.com/goccy/go-json/internal/encoder" +) -func UnorderedMap() func(EncodeOption) EncodeOption { - return func(opt EncodeOption) EncodeOption { - return opt | EncodeOptionUnorderedMap +type EncodeOption = encoder.Option +type EncodeOptionFunc func(*EncodeOption) + +// UnorderedMap doesn't sort when encoding map type. +func UnorderedMap() EncodeOptionFunc { + return func(opt *EncodeOption) { + opt.Flag |= encoder.UnorderedMapOption + } +} + +// Debug outputs debug information when panic occurs during encoding. +func Debug() EncodeOptionFunc { + return func(opt *EncodeOption) { + opt.Flag |= encoder.DebugOption } } -func Debug() func(EncodeOption) EncodeOption { - return func(opt EncodeOption) EncodeOption { - return opt | EncodeOptionDebug +// Colorize add an identifier for coloring to the string of the encoded result. +func Colorize(scheme *ColorScheme) EncodeOptionFunc { + return func(opt *EncodeOption) { + opt.Flag |= encoder.ColorizeOption + opt.ColorScheme = scheme + } +} + +type DecodeOption = decoder.Option +type DecodeOptionFunc func(*DecodeOption) + +// DecodeFieldPriorityFirstWin +// in the default behavior, go-json, like encoding/json, +// will reflect the result of the last evaluation when a field with the same name exists. +// This option allow you to change this behavior. +// this option reflects the result of the first evaluation if a field with the same name exists. +// This behavior has a performance advantage as it allows the subsequent strings to be skipped if all fields have been evaluated. +func DecodeFieldPriorityFirstWin() DecodeOptionFunc { + return func(opt *DecodeOption) { + opt.Flags |= decoder.FirstWinOption } } |