From 2b90888901946285d3834a7d534894e3acd1c85f Mon Sep 17 00:00:00 2001 From: charlie <3140647@qq.com> Date: Tue, 30 Sep 2025 10:24:35 +0800 Subject: [PATCH] default options --- optiongs.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/optiongs.go b/optiongs.go index 9bb5f10..43bc729 100644 --- a/optiongs.go +++ b/optiongs.go @@ -15,6 +15,7 @@ type options struct { caseSensitive bool // 复制时大小写敏感 must bool // 只复制具有must标识的字段 detectCircularRefs bool // 检测循环引用 + skipFields []string // 忽略字段 fieldNameMapping map[string]string // 字段名转映射 converters map[converterPair]convertFunc // 根据源和目标类型处理的类型转换器v convertByName map[string]convertFunc // 根据名称处理的类型转换器 @@ -22,6 +23,13 @@ type options struct { timeFormats map[reflect.Type]string // 时间格式 } +var ( + defaultOptions = &options{ + tagName: defaultTag, + maxDepth: noDepthLimited, + } +) + type option func(*options) type TypeConverter struct { @@ -38,6 +46,10 @@ type converterPair struct { } func getOpt(opts ...option) *options { + if len(opts) == 0 { + return defaultOptions + } + opt := &options{ maxDepth: noDepthLimited, tagName: defaultTag, @@ -186,6 +198,12 @@ func WithDefaultTimeFormat(format string) option { } } +func WitSkipFields(fields ...string) option { + return func(o *options) { + o.skipFields = fields + } +} + // WithTagName 添加标签名 func WithTagName(tagName string) option { return func(o *options) {