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-29 17:18:27 +08:00
parent 830a870158
commit f6ecb9be4b
4 changed files with 62 additions and 7 deletions

View File

@ -2,6 +2,7 @@ package structs
import (
"reflect"
"strings"
"github.com/charlienet/go-mixed/expr"
)
@ -20,10 +21,20 @@ func parseField(fi reflect.StructField, opt option) 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,
ignore: (name == "-" && opt.Ignore) || isSkipField(fi.Name, opt.SkipFields),
}
}
func (f field) shouldIgnore(s reflect.Value) bool {
return f.ignore || (s.IsZero() && f.ignoreEmpty)
}
func isSkipField(name string, skips []string) bool {
for _, v := range skips {
if strings.EqualFold(v, name) {
return true
}
}
return false
}