import "go.tools.go.types" func main() { t := types.NewNamed(types.NewTypeName(0, nil, "MyType", nil), nil, nil) fmt.Println(t.Obj().Name()) }
import "go.tools.go.types" type Person struct { name string age int } func main() { p := Person{name: "John", age: 30} t := types.NewStruct([]*types.Var{ types.NewField(0, nil, "name", types.NewString()), types.NewField(0, nil, "age", types.NewInt()), }, nil) fmt.Println(t.Field(0).Name()) // Output: name }This example creates a new struct type for the `Person` struct and prints the name of its first field using the `Field(0).Name()` method. Package library: `go.tools.go.types`