Skip to content

Commit

Permalink
feat: utility function and file serving features support
Browse files Browse the repository at this point in the history
  • Loading branch information
hokamsingh committed Aug 18, 2024
1 parent 01d9882 commit fc61fa2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
17 changes: 17 additions & 0 deletions internal/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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
}
4 changes: 4 additions & 0 deletions pkg/lessgo/less.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

0 comments on commit fc61fa2

Please sign in to comment.