MCPcopy
hub / github.com/livebud/bud / loadController

Method loadController

framework/controller/loader.go:63–104  ·  view source on GitHub ↗
(controllerPath string)

Source from the content-addressed store, hash-verified

61}
62
63func (l *loader) loadController(controllerPath string) *Controller {
64 des, err := fs.ReadDir(l.fsys, controllerPath)
65 if err != nil {
66 l.Bail(err)
67 } else if len(des) == 0 {
68 l.Bail(fs.ErrNotExist)
69 }
70 controller := new(Controller)
71 controller.Path = l.loadControllerPath(controllerPath)
72 controller.Name = l.loadControllerName(controller.Path)
73 controller.Pascal = gotext.Pascal(controller.Name)
74 // TODO: rename to route
75 controller.Route = l.loadControllerRoute(controller.Path)
76 shouldParse := false
77 for _, de := range des {
78 if !de.IsDir() && valid.ControllerFile(de.Name()) {
79 shouldParse = true
80 continue
81 }
82 if de.IsDir() && valid.Dir(de.Name()) {
83 subController := l.loadController(path.Join(controllerPath, de.Name()))
84 if subController == nil {
85 continue
86 }
87 controller.Controllers = append(controller.Controllers, subController)
88 continue
89 }
90 }
91 if !shouldParse {
92 return controller
93 }
94 pkg, err := l.parser.Parse(controllerPath)
95 if err != nil {
96 l.Bail(err)
97 }
98 stct := pkg.Struct("Controller")
99 if stct == nil {
100 return controller
101 }
102 controller.Actions = l.loadActions(controller, stct)
103 return controller
104}
105
106func (l *loader) loadControllerPath(controllerPath string) string {
107 parts := strings.SplitN(controllerPath, "/", 2)

Callers 1

LoadMethod · 0.95

Calls 13

loadControllerPathMethod · 0.95
loadControllerNameMethod · 0.95
loadControllerRouteMethod · 0.95
loadActionsMethod · 0.95
ControllerFileFunction · 0.92
DirFunction · 0.92
BailMethod · 0.80
NameMethod · 0.65
ReadDirMethod · 0.45
PascalMethod · 0.45
IsDirMethod · 0.45
ParseMethod · 0.45

Tested by

no test coverage detected