Skip to content

Commit

Permalink
bake: capture function type when reading AST
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidGamba committed Jan 13, 2024
1 parent d188942 commit 8ad6dd1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
11 changes: 10 additions & 1 deletion bake/ast.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
package main

import (
"bytes"
"fmt"
"go/ast"
"go/parser"
"go/printer"
"go/token"

"golang.org/x/tools/go/packages"
)

type FuncDecl struct {
Description string
Type string
}

// m: map of function name to function information
Expand Down Expand Up @@ -41,7 +44,13 @@ func GetFuncDeclForPackage(dir string, m *map[string]FuncDecl) error {
if x.Name.IsExported() {
name := x.Name.Name
description := x.Doc.Text()
(*m)[name] = FuncDecl{Description: description}
var buf bytes.Buffer
printer.Fprint(&buf, fset, x.Type)
Logger.Printf("file: %s, name: %s, type: %s\n", file, name, buf.String())
(*m)[name] = FuncDecl{
Description: description,
Type: buf.String(),
}
}
}
return true
Expand Down
5 changes: 5 additions & 0 deletions bake/examples/website/bake/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,3 +206,8 @@ func Clean(opt *getoptions.GetOpt) getoptions.CommandFn {
return nil
}
}

// notused - Not used because it doesn't return a getoptions.CommandFn
func NotUsed() error {
return nil
}

0 comments on commit 8ad6dd1

Please sign in to comment.