Skip to content

Commit

Permalink
finds fields by json struct tag
Browse files Browse the repository at this point in the history
  • Loading branch information
codyleyhan committed Aug 22, 2018
1 parent b8695fb commit 95b6f32
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions codegen/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package codegen
import (
"fmt"
"go/types"
"reflect"
"regexp"
"strings"

Expand Down Expand Up @@ -128,6 +129,14 @@ func findField(typ *types.Struct, name string) *types.Var {
if strings.EqualFold(field.Name(), name) {
return field
}

tags := reflect.StructTag(typ.Tag(i))

if val, ok := tags.Lookup("json"); ok {
if strings.EqualFold(val, name) {
return field
}
}
}
return nil
}
Expand Down

0 comments on commit 95b6f32

Please sign in to comment.