mirror of
https://github.com/charlienet/go-mixed.git
synced 2025-07-18 16:42:41 +08:00
结构体转map
This commit is contained in:
45
structs/utils.go
Normal file
45
structs/utils.go
Normal file
@ -0,0 +1,45 @@
|
||||
package structs
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
)
|
||||
|
||||
type optionFunc func(*option)
|
||||
|
||||
type option struct {
|
||||
IgnoreEmpty bool
|
||||
DeepCopy bool
|
||||
Omitempty bool
|
||||
}
|
||||
|
||||
func IgnoreEmpty() optionFunc {
|
||||
return func(o *option) {
|
||||
o.IgnoreEmpty = true
|
||||
}
|
||||
}
|
||||
|
||||
func DeepCopy() optionFunc {
|
||||
return func(o *option) {
|
||||
o.DeepCopy = true
|
||||
}
|
||||
}
|
||||
|
||||
func Omitempty() optionFunc {
|
||||
return func(o *option) {
|
||||
o.Omitempty = true
|
||||
}
|
||||
}
|
||||
|
||||
func createOptions(opts []optionFunc) *option {
|
||||
o := &option{}
|
||||
for _, f := range opts {
|
||||
f(o)
|
||||
}
|
||||
|
||||
return o
|
||||
}
|
||||
|
||||
func shouldIgnore(v reflect.Value, ignoreEmpty bool) bool {
|
||||
return ignoreEmpty && v.IsZero()
|
||||
}
|
||||
|
Reference in New Issue
Block a user