From 79afa3ec1c4349fc7e69c18a190b6962e0cad2a7 Mon Sep 17 00:00:00 2001 From: jaemin Date: Wed, 4 Mar 2015 19:02:03 +0900 Subject: [PATCH] refactor Field to have defaultTag field which value is from parent struct --- field.go | 7 ++++--- structs.go | 5 +++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/field.go b/field.go index a7a134d..4b5e15b 100644 --- a/field.go +++ b/field.go @@ -14,8 +14,9 @@ var ( // Field represents a single struct field that encapsulates high level // functions around the field. type Field struct { - value reflect.Value - field reflect.StructField + value reflect.Value + field reflect.StructField + defaultTag string } // Tag returns the value associated with key in the tag string. If there is no @@ -92,7 +93,7 @@ func (f *Field) Set(val interface{}) error { // // It panics if field is not exported or if field's kind is not struct func (f *Field) Fields() []*Field { - return getFields(f.value, DefaultTagName) + return getFields(f.value, f.defaultTag) } // Field returns the field from a nested struct. It panics if the nested struct diff --git a/structs.go b/structs.go index 0a1fd51..47bf354 100644 --- a/structs.go +++ b/structs.go @@ -222,8 +222,9 @@ func (s *Struct) FieldOk(name string) (*Field, bool) { } return &Field{ - field: field, - value: s.value.FieldByName(name), + field: field, + value: s.value.FieldByName(name), + defaultTag: s.TagName, }, true }