Skip to content

Commit 8a3ef38

Browse files
committed
Add document for options
1 parent 5c39787 commit 8a3ef38

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

option.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,21 @@ import (
88
type EncodeOption = encoder.Option
99
type EncodeOptionFunc func(*EncodeOption)
1010

11+
// UnorderedMap doesn't sort when encoding map type.
1112
func UnorderedMap() EncodeOptionFunc {
1213
return func(opt *EncodeOption) {
1314
opt.Flag |= encoder.UnorderedMapOption
1415
}
1516
}
1617

18+
// Debug outputs debug information when panic occurs during encoding.
1719
func Debug() EncodeOptionFunc {
1820
return func(opt *EncodeOption) {
1921
opt.Flag |= encoder.DebugOption
2022
}
2123
}
2224

25+
// Colorize add an identifier for coloring to the string of the encoded result.
2326
func Colorize(scheme *ColorScheme) EncodeOptionFunc {
2427
return func(opt *EncodeOption) {
2528
opt.Flag |= encoder.ColorizeOption
@@ -30,6 +33,12 @@ func Colorize(scheme *ColorScheme) EncodeOptionFunc {
3033
type DecodeOption = decoder.Option
3134
type DecodeOptionFunc func(*DecodeOption)
3235

36+
// DecodeFieldPriorityFirstWin
37+
// in the default behavior, go-json, like encoding/json,
38+
// will reflect the result of the last evaluation when a field with the same name exists.
39+
// This option allow you to change this behavior.
40+
// this option reflects the result of the first evaluation if a field with the same name exists.
41+
// This behavior has a performance advantage as it allows the subsequent strings to be skipped if all fields have been evaluated.
3342
func DecodeFieldPriorityFirstWin() DecodeOptionFunc {
3443
return func(opt *DecodeOption) {
3544
opt.Flag |= decoder.FirstWinOption

0 commit comments

Comments
 (0)