From 95b6f323a880d9034cacf048f0db0c783ca772e9 Mon Sep 17 00:00:00 2001 From: Cody Ley-Han Date: Wed, 22 Aug 2018 13:47:34 -0700 Subject: [PATCH] finds fields by json struct tag --- codegen/util.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/codegen/util.go b/codegen/util.go index fae94adead..4f6dc66b01 100644 --- a/codegen/util.go +++ b/codegen/util.go @@ -3,6 +3,7 @@ package codegen import ( "fmt" "go/types" + "reflect" "regexp" "strings" @@ -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 }