1
0
mirror of https://github.com/charlienet/go-mixed.git synced 2025-07-18 00:22:41 +08:00
This commit is contained in:
2022-04-24 17:06:40 +08:00
parent d3f727e54d
commit 78c957c98e
10 changed files with 270 additions and 83 deletions

29
structs/field.go Normal file
View File

@ -0,0 +1,29 @@
package structs
import (
"reflect"
"github.com/charlienet/go-mixed/expr"
)
type field struct {
name string
tagName string
ignoreEmpty bool
ignore bool
}
func parseField(fi reflect.StructField, opt option) field {
name, opts := parseTag(fi.Tag.Get(opt.TagName))
return field{
name: fi.Name,
tagName: expr.If(isValidTag(name), name, expr.If(opt.NameConverter != nil, opt.NameConverter(fi.Name), fi.Name)),
ignoreEmpty: opt.IgnoreEmpty || (opts.Contains("omitempty") && opt.Omitempty),
ignore: name == "-" && opt.Ignore,
}
}
func (f field) shouldIgnore(s reflect.Value) bool {
return f.ignore || (s.IsZero() && f.ignoreEmpty)
}