mirror of
https://github.com/charlienet/go-mixed.git
synced 2025-07-18 16:42:41 +08:00
名称转换
This commit is contained in:
@ -2,11 +2,14 @@ package structs
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
|
||||
"github.com/charlienet/go-mixed/json"
|
||||
)
|
||||
|
||||
type optionFunc func(*option)
|
||||
|
||||
type option struct {
|
||||
NameFunc func(string) string
|
||||
IgnoreEmpty bool
|
||||
DeepCopy bool
|
||||
Omitempty bool
|
||||
@ -30,8 +33,23 @@ func Omitempty() optionFunc {
|
||||
}
|
||||
}
|
||||
|
||||
func Lcfirst() optionFunc {
|
||||
return func(o *option) {
|
||||
o.NameFunc = json.Lcfirst
|
||||
}
|
||||
}
|
||||
|
||||
func Camel2Case() optionFunc {
|
||||
return func(o *option) {
|
||||
o.NameFunc = json.Camel2Case
|
||||
}
|
||||
}
|
||||
|
||||
func createOptions(opts []optionFunc) *option {
|
||||
o := &option{}
|
||||
o := &option{
|
||||
NameFunc: func(s string) string { return s },
|
||||
}
|
||||
|
||||
for _, f := range opts {
|
||||
f(o)
|
||||
}
|
||||
@ -42,4 +60,3 @@ func createOptions(opts []optionFunc) *option {
|
||||
func shouldIgnore(v reflect.Value, ignoreEmpty bool) bool {
|
||||
return ignoreEmpty && v.IsZero()
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user