1 Star 2 Fork 0

阿债 / fiber-u8l

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
option.go 2.22 KB
一键复制 编辑 原始数据 按行查看 历史
阿债 提交于 2022-01-22 14:36 . 升级到fiber2.25.0
package json
import (
"gitee.com/azhai/fiber-u8l/v2/internal/go-json/decoder"
"gitee.com/azhai/fiber-u8l/v2/internal/go-json/encoder"
)
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
}
}
// DisableHTMLEscape disables escaping of HTML characters ( '&', '<', '>' ) when encoding string.
func DisableHTMLEscape() EncodeOptionFunc {
return func(opt *EncodeOption) {
opt.Flag &= ^encoder.HTMLEscapeOption
}
}
// DisableNormalizeUTF8
// By default, when encoding string, UTF8 characters in the range of 0x80 - 0xFF are processed by applying \ufffd for invalid code and escaping for \u2028 and \u2029.
// This option disables this behaviour. You can expect faster speeds by applying this option, but be careful.
// encoding/json implements here: https://github.com/golang/go/blob/6178d25fc0b28724b1b5aec2b1b74fc06d9294c7/src/encoding/json/encode.go#L1067-L1093.
func DisableNormalizeUTF8() EncodeOptionFunc {
return func(opt *EncodeOption) {
opt.Flag &= ^encoder.NormalizeUTF8Option
}
}
// Debug outputs debug information when panic occurs during encoding.
func Debug() EncodeOptionFunc {
return func(opt *EncodeOption) {
opt.Flag |= encoder.DebugOption
}
}
// 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
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/azhai/fiber-u8l.git
git@gitee.com:azhai/fiber-u8l.git
azhai
fiber-u8l
fiber-u8l
v2.30.0

搜索帮助

344bd9b3 5694891 D2dac590 5694891