package main import ( "go/ast" "go/token" ) func main() { fields := []*ast.Field{ &ast.Field{ Names: []*ast.Ident{ast.NewIdent("foo")}, Type: ast.NewIdent("int"), }, &ast.Field{ Names: []*ast.Ident{ast.NewIdent("bar")}, Type: ast.NewIdent("string"), }, } structType := &ast.StructType{ Fields: &ast.FieldList{ List: fields, }, } decl := &ast.GenDecl{ Tok: token.TYPE, Specs: []ast.Spec{ &ast.TypeSpec{ Name: ast.NewIdent("MyStruct"), Type: structType, }, }, } ast.Print(nil, decl) }This code creates a `FieldList` with two fields, each with a name and a type. It then creates a `StructType` with the `Fields` field set to the `FieldList`, and finally uses these to generate a `TypeSpec`, which is then printed to the console. The `go.ast` package is part of the standard library included with Go.