default options

This commit is contained in:
2025-09-30 10:24:35 +08:00
parent 715033f650
commit 2b90888901

View File

@@ -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) {