import ( "go/types" ) type Person struct { Name string Age int Height float64 } func main() { typ := types.NewStruct([]*types.Var{ types.NewVar(0, nil, "Name", types.NewNamed(types.NewTypeName(0, nil, "string", nil), types.Typ[types.String])), types.NewVar(0, nil, "Age", types.Typ[types.Int]), types.NewVar(0, nil, "Height", types.Typ[types.Float64])), }, nil) fmt.Println(typ) }
import ( "go/types" ) func main() { named := types.NewNamed( types.NewTypeName(0, nil, "MyInt", nil), types.Typ[types.Int], nil, ) fmt.Println(named) }This code creates a new named type MyInt with the underlying type of int using the NewNamed function from the go.types package. Package Library: Standard Library.