Skip to content

Commit

Permalink
fix: skip omited tag
Browse files Browse the repository at this point in the history
Change-Id: Id5bcf973de5404551a8f3d9f177d16c01de8ee44
  • Loading branch information
andeya committed Jul 21, 2022
1 parent 5ff4a5a commit c7e48de
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,5 @@ _testmain.go

# idea ignore
.idea/

.vscode/
18 changes: 13 additions & 5 deletions tagexpr.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,11 +286,15 @@ func (vm *VM) registerStructLocked(structType reflect.Type) (*structVM, error) {
var sub *structVM
for i := 0; i < numField; i++ {
structField = structType.Field(i)
field, err := s.newFieldVM(structField)
field, ok, err := s.newFieldVM(structField)
if err != nil {
s.err = err
return nil, err
}
// skip omited tag
if !ok {
continue
}
switch field.elemKind {
default:
field.setUnsupportGetter()
Expand Down Expand Up @@ -410,16 +414,20 @@ func (vm *VM) newStructVM() *structVM {
}
}

func (s *structVM) newFieldVM(structField reflect.StructField) (*fieldVM, error) {
func (s *structVM) newFieldVM(structField reflect.StructField) (*fieldVM, bool, error) {
var tag = structField.Tag.Get(s.vm.tagName)
if tag == tagOmit {
return nil, false, nil
}
f := &fieldVM{
structField: structField,
exprs: make(map[string]*Expr, 8),
origin: s,
fieldSelector: structField.Name,
}
err := f.parseExprs(structField.Tag.Get(s.vm.tagName))
err := f.parseExprs(tag)
if err != nil {
return nil, err
return nil, false, err
}
s.fields[f.fieldSelector] = f
s.fieldSelectorList = append(s.fieldSelectorList, f.fieldSelector)
Expand Down Expand Up @@ -450,7 +458,7 @@ func (s *structVM) newFieldVM(structField reflect.StructField) (*fieldVM, error)
return v
}

return f, nil
return f, true, nil
}

func (f *fieldVM) ensureInit(v reflect.Value) {
Expand Down

0 comments on commit c7e48de

Please sign in to comment.