Standard library / go/types

go/types.Struct.Field()

Returns the field object at a zero-based index. Expected stdout: 'X\n'.

Formal Syntax & Structure

go syntaxgo
func (s *Struct) Field(i int) *Var

Parameters & Attributes

NameTypeDescription
iintZero-based member index.

Return Value

*Var

Returns the field object at a zero-based index.

Working Example

Example Snippetgo
package main
import (  "fmt"  "go/types")
func main() {  t := types.NewStruct([]*types.Var{types.NewField(0, nil, "X", types.Typ[types.Int], false)}, nil)  fmt.Println(t.Field(0).Name())}
Go Reference