package main
import ( "fmt")
type Inputs struct { Name string `json:"name"` Age int `json:"age"`}
type Outputs struct { Number float `json:"number"`}
func main() {
fmt.Println("Hello World!")}
package main
import ( "fmt" "go/ast" "go/parser" "go/token" "log")
func main() {
fset := token.NewFileSet() file, err := parser.ParseFile(fset, "sample/main.go", nil, 0) if err != nil { log.Fatal(err) } ast.Walk(VisitorFunc(FindTypes), file)
}
type VisitorFunc func(n ast.Node) ast.Visitor
func (f VisitorFunc) Visit(n ast.Node) ast.Visitor { return f(n)}
func FindTypes(n ast.Node) ast.Visitor { switch n := n.(type) { case *ast.Package: return VisitorFunc(FindTypes) case *ast.File: return VisitorFunc(FindTypes) case *ast.GenDecl: if n.Tok == token.TYPE { return VisitorFunc(FindTypes) } case *ast.TypeSpec: if n.Name.Name == "Inputs" { //We have hit the inputs struct fmt.Println(n.Name.Name) } if n.Name.Name == "Outputs" { //We have hit the outputs struct fmt.Println(n.Name.Name) } } return nil}