modweb/manager.go

32 lines
824 B
Go

package modweb
import (
"github.com/gofiber/fiber/v2"
"github.com/gofiber/session/v2"
"net/http"
)
type ModuleManager struct {
module Module
app *App
}
func (mm *ModuleManager) RegisterViews(system http.FileSystem) {
mm.app.viewsFs.Register(mm.module.Name(), system)
}
func (mm *ModuleManager) Fiber(handlers ...fiber.Handler) fiber.Router {
return mm.app.fiber.Group("/" + mm.module.Name() + "/", handlers...)
}
func (mm *ModuleManager) Render(ctx *fiber.Ctx, template string, data fiber.Map) error {
return ctx.Render(mm.module.Name() + "/" + template, mm.app.data(ctx, data), "layouts/main")
}
func (mm *ModuleManager) Session(ctx *fiber.Ctx) *session.Store {
return mm.app.sessions.Get(ctx)
}
func (mm *ModuleManager) SetHomepage(template string) {
mm.app.homepage = mm.module.Name() + "/" + template
}