1
0
mirror of https://github.com/charlienet/go-mixed.git synced 2025-07-18 00:22:41 +08:00
Files
go-mixed/structs/utils.go
2022-04-22 14:30:37 +08:00

46 lines
611 B
Go

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()
}