47
47
// method signature, without a receiver, and the Func field is nil.
50
// MethodByName returns the method with that name in the type's
51
// method set and a boolean indicating if the method was found.
53
// For a non-interface type T or *T, the returned Method's Type and Func
54
// fields describe a function whose first argument is the receiver.
56
// For an interface type, the returned Method's Type field gives the
57
// method signature, without a receiver, and the Func field is nil.
58
MethodByName(string) (Method, bool)
50
60
// NumMethod returns the number of methods in the type's method set.
295
305
// interfaceType represents an interface type.
296
306
type interfaceType struct {
297
commonType "interface"
307
commonType `reflect:"interface"`
298
308
methods []imethod
301
311
// mapType represents a map type.
302
312
type mapType struct {
313
commonType `reflect:"map"`
304
314
key *runtime.Type
305
315
elem *runtime.Type
308
318
// ptrType represents a pointer type.
309
319
type ptrType struct {
320
commonType `reflect:"ptr"`
311
321
elem *runtime.Type
314
324
// sliceType represents a slice type.
315
325
type sliceType struct {
326
commonType `reflect:"slice"`
317
327
elem *runtime.Type
461
473
return len(t.methods)
476
func (t *uncommonType) MethodByName(name string) (m Method, ok bool) {
481
for i := range t.methods {
483
if p.name != nil && *p.name == name {
484
return t.Method(i), true
464
490
// TODO(rsc): 6g supplies these, but they are not
465
491
// as efficient as they could be: they have commonType
466
492
// as the receiver instead of *commonType.
480
506
return t.uncommonType.Method(i)
509
func (t *commonType) MethodByName(name string) (m Method, ok bool) {
510
if t.Kind() == Interface {
511
tt := (*interfaceType)(unsafe.Pointer(t))
512
return tt.MethodByName(name)
514
return t.uncommonType.MethodByName(name)
483
517
func (t *commonType) PkgPath() string {
484
518
return t.uncommonType.PkgPath()
636
670
m.PkgPath = *p.pkgPath
638
672
m.Type = toType(p.typ)
642
677
// NumMethod returns the number of interface methods in the type's method set.
643
678
func (t *interfaceType) NumMethod() int { return len(t.methods) }
680
// MethodByName method with the given name in the type's method set.
681
func (t *interfaceType) MethodByName(name string) (m Method, ok bool) {
686
for i := range t.methods {
689
return t.Method(i), true
645
695
type StructField struct {
646
696
PkgPath string // empty for uppercase Name
705
// A StructTag is the tag string in a struct field.
707
// By convention, tag strings are a concatenation of
708
// optionally space-separated key:"value" pairs.
709
// Each key is a non-empty string consisting of non-control
710
// characters other than space (U+0020 ' '), quote (U+0022 '"'),
711
// and colon (U+003A ':'). Each value is quoted using U+0022 '"'
712
// characters and Go string literal syntax.
713
type StructTag string
715
// Get returns the value associated with key in the tag string.
716
// If there is no such key in the tag, Get returns the empty string.
717
// If the tag does not have the conventional format, the value
718
// returned by Get is unspecified,
719
func (tag StructTag) Get(key string) string {
721
// skip leading space
723
for i < len(tag) && tag[i] == ' ' {
732
// a space or a quote is a syntax error
734
for i < len(tag) && tag[i] != ' ' && tag[i] != ':' && tag[i] != '"' {
737
if i+1 >= len(tag) || tag[i] != ':' || tag[i+1] != '"' {
740
name := string(tag[:i])
743
// scan quoted string to find value
745
for i < len(tag) && tag[i] != '"' {
754
qvalue := string(tag[:i+1])
758
value, _ := strconv.Unquote(qvalue)
655
765
// Field returns the i'th struct field.
656
766
func (t *structType) Field(i int) (f StructField) {
657
767
if i < 0 || i >= len(t.fields) {