default options
This commit is contained in:
18
optiongs.go
18
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) {
|
||||
|
||||
Reference in New Issue
Block a user