package main import ( "fmt" "go/types" ) func main() { inputs := []*types.Var{ types.NewVar(token.NoPos, nil, "", types.Typ[types.Int]), types.NewVar(token.NoPos, nil, "", types.Typ[types.String]), } outputs := []*types.Var{ types.NewVar(token.NoPos, nil, "", types.Typ[types.Bool]), } funcType := types.NewSignature(nil, nil, inputs, outputs, false) fmt.Printf("%#v\n", funcType) }
package main import ( "fmt" "go/types" ) func main() { var funcType *types.Signature expr, err := parser.ParseExpr(`func(int, string) bool`) if err == nil { funcType, _ = types.FuncFromExpr(expr, types.NewPackage("main", "")) } fmt.Printf("%#v\n", funcType) }This example uses the `parser` package to parse a Go function signature from a string and then creates a `FuncType` from it. In both examples, the `go/types` package is used.