1
0
mirror of https://github.com/charlienet/go-mixed.git synced 2025-07-18 16:42:41 +08:00

结构体转map

This commit is contained in:
2022-04-22 14:30:37 +08:00
parent 2771310fe2
commit efc8210d97
6 changed files with 184 additions and 0 deletions

45
structs/utils.go Normal file
View 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()
}