@@ -360,7 +360,7 @@ type Type interface {
360360 // and FieldByNameFunc returns no match.
361361 // This behavior mirrors Go's handling of name lookup in
362362 // structs containing embedded fields.
363- // FieldByNameFunc(match func(string) bool) (StructField, bool)
363+ FieldByNameFunc (match func (string ) bool ) (StructField , bool )
364364
365365 // In returns the type of a function type's i'th input parameter.
366366 // It panics if the type's Kind is not Func.
@@ -710,11 +710,11 @@ func (t *rawType) rawField(n int) rawStructField {
710710 return rawStructFieldFromPointer (descriptor , field .fieldType , data , flagsByte , name , offset )
711711}
712712
713- // rawFieldByName returns nearly the same value as FieldByName but without converting the
713+ // rawFieldByNameFunc returns nearly the same value as FieldByNameFunc but without converting the
714714// Type member to an interface.
715715//
716716// For internal use only.
717- func (t * rawType ) rawFieldByName ( n string ) (rawStructField , []int , bool ) {
717+ func (t * rawType ) rawFieldByNameFunc ( match func ( string ) bool ) (rawStructField , []int , bool ) {
718718 if t .Kind () != Struct {
719719 panic (& TypeError {"Field" })
720720 }
@@ -757,7 +757,7 @@ func (t *rawType) rawFieldByName(n string) (rawStructField, []int, bool) {
757757
758758 name := readStringZ (data )
759759 data = unsafe .Add (data , len (name ))
760- if name == n {
760+ if match ( name ) {
761761 found = append (found , result {
762762 rawStructFieldFromPointer (descriptor , field .fieldType , data , flagsByte , name , offset ),
763763 append (ll .index , int (i )),
@@ -1087,7 +1087,28 @@ func (t *rawType) FieldByName(name string) (StructField, bool) {
10871087 panic (TypeError {"FieldByName" })
10881088 }
10891089
1090- field , index , ok := t .rawFieldByName (name )
1090+ field , index , ok := t .rawFieldByNameFunc (func (n string ) bool { return n == name })
1091+ if ! ok {
1092+ return StructField {}, false
1093+ }
1094+
1095+ return StructField {
1096+ Name : field .Name ,
1097+ PkgPath : field .PkgPath ,
1098+ Type : field .Type , // note: converts rawType to Type
1099+ Tag : field .Tag ,
1100+ Anonymous : field .Anonymous ,
1101+ Offset : field .Offset ,
1102+ Index : index ,
1103+ }, true
1104+ }
1105+
1106+ func (t * rawType ) FieldByNameFunc (match func (string ) bool ) (StructField , bool ) {
1107+ if t .Kind () != Struct {
1108+ panic (TypeError {"FieldByNameFunc" })
1109+ }
1110+
1111+ field , index , ok := t .rawFieldByNameFunc (match )
10911112 if ! ok {
10921113 return StructField {}, false
10931114 }
0 commit comments