diff --git a/internal/utils/utils.go b/internal/utils/utils.go index 5cdf207..cdb01c1 100644 --- a/internal/utils/utils.go +++ b/internal/utils/utils.go @@ -3,6 +3,11 @@ package utils import ( "os" "path/filepath" + + "github.com/hokamsingh/lessgo/internal/core/controller" + "github.com/hokamsingh/lessgo/internal/core/di" + "github.com/hokamsingh/lessgo/internal/core/module" + "github.com/hokamsingh/lessgo/internal/core/router" ) func GetFolderPath(folderName string) (string, error) { @@ -22,3 +27,15 @@ func GetFolderPath(folderName string) (string, error) { return folderPath, nil } + +func RegisterModuleControllers(r *router.Router, container *di.Container, module module.Module) error { + for _, ctrl := range module.Controllers { + if c, ok := ctrl.(controller.Controller); ok { + // Inject dependencies + container.Inject(c) + // Register routes + c.RegisterRoutes(r.Mux) + } + } + return nil +} diff --git a/pkg/lessgo/less.go b/pkg/lessgo/less.go index c44e2a0..f36be00 100644 --- a/pkg/lessgo/less.go +++ b/pkg/lessgo/less.go @@ -86,3 +86,7 @@ func ServeStatic(pathPrefix, dir string) http.Handler { func GetFolderPath(folderName string) (string, error) { return utils.GetFolderPath(folderName) } + +func RegisterModuleControllers(r *router.Router, container *di.Container, module module.Module) error { + return utils.RegisterModuleControllers(r, container, module) +}