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

Function loadExternalReceiverMethods

scripts/dbgen/main.go:331–380  ·  view source on GitHub ↗
(
	dirPath string,
	excludeFile string,
	structName string,
)

Source from the content-addressed store, hash-verified

329}
330
331func loadExternalReceiverMethods(
332 dirPath string,
333 excludeFile string,
334 structName string,
335) (map[string]struct{}, error) {
336 methods := make(map[string]struct{})
337 entries, err := os.ReadDir(dirPath)
338 if err != nil {
339 return nil, xerrors.Errorf("read dir %s: %w", dirPath, err)
340 }
341
342 for _, entry := range entries {
343 name := entry.Name()
344 if entry.IsDir() || name == excludeFile || !strings.HasSuffix(name, ".go") || strings.HasSuffix(name, "_test.go") {
345 continue
346 }
347
348 contents, err := os.ReadFile(filepath.Join(dirPath, name))
349 if err != nil {
350 return nil, xerrors.Errorf("read %s: %w", name, err)
351 }
352 f, err := decorator.Parse(contents)
353 if err != nil {
354 return nil, xerrors.Errorf("parse %s: %w", name, err)
355 }
356 for _, decl := range f.Decls {
357 funcDecl, ok := decl.(*dst.FuncDecl)
358 if !ok || funcDecl.Recv == nil || len(funcDecl.Recv.List) == 0 {
359 continue
360 }
361
362 var ident *dst.Ident
363 switch recv := funcDecl.Recv.List[0].Type.(type) {
364 case *dst.Ident:
365 ident = recv
366 case *dst.StarExpr:
367 ident, ok = recv.X.(*dst.Ident)
368 if !ok {
369 continue
370 }
371 }
372 if ident == nil || ident.Name != structName {
373 continue
374 }
375 methods[funcDecl.Name.Name] = struct{}{}
376 }
377 }
378
379 return methods, nil
380}
381
382func loadInterfaceFuncs(f *dst.File, interfaceName string) ([]querierFunction, error) {
383 var querier *dst.InterfaceType

Callers 1

Calls 5

ReadDirMethod · 0.80
NameMethod · 0.65
ReadFileMethod · 0.65
ParseMethod · 0.65
ErrorfMethod · 0.45

Tested by

no test coverage detected