MCPcopy Index your code
hub / github.com/coder/coder / compileFuncDecl

Function compileFuncDecl

scripts/dbgen/main.go:266–283  ·  view source on GitHub ↗

compileFuncDecl extracts the function declaration from the given code.

(code string)

Source from the content-addressed store, hash-verified

264
265// compileFuncDecl extracts the function declaration from the given code.
266func compileFuncDecl(code string) (*dst.FuncDecl, error) {
267 f, err := decorator.Parse(fmt.Sprintf(`package stub
268
269func stub() {
270 %s
271}`, strings.TrimSpace(code)))
272 if err != nil {
273 return nil, err
274 }
275 if len(f.Decls) != 1 {
276 return nil, xerrors.Errorf("expected 1 decl, got %d", len(f.Decls))
277 }
278 decl, ok := f.Decls[0].(*dst.FuncDecl)
279 if !ok {
280 return nil, xerrors.Errorf("expected func decl, got %T", f.Decls[0])
281 }
282 return decl, nil
283}
284
285type querierFunction struct {
286 // Name is the name of the function. Like "GetUserByID"

Callers 1

Calls 2

ParseMethod · 0.65
ErrorfMethod · 0.45

Tested by

no test coverage detected