modweb/manager.go

33 lines
824 B
Go
Raw Normal View History

2020-11-11 23:51:23 +00:00
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) {
2020-11-16 20:19:37 +00:00
mm.app.viewsFs.Register(mm.module.Name(), system)
2020-11-11 23:51:23 +00:00
}
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 {
2020-11-16 20:19:37 +00:00
return ctx.Render(mm.module.Name() + "/" + template, mm.app.data(ctx, data), "layouts/main")
2020-11-11 23:51:23 +00:00
}
func (mm *ModuleManager) Session(ctx *fiber.Ctx) *session.Store {
return mm.app.sessions.Get(ctx)
}
2020-11-16 20:19:37 +00:00
func (mm *ModuleManager) SetHomepage(template string) {
mm.app.homepage = mm.module.Name() + "/" + template
}