parcoursmob/handlers/application/application.go

42 lines
1.2 KiB
Go
Raw Normal View History

package application
import (
"net/http"
"git.coopgo.io/coopgo-apps/parcoursmob/renderer"
"git.coopgo.io/coopgo-apps/parcoursmob/services"
cache "git.coopgo.io/coopgo-apps/parcoursmob/utils/storage"
"git.coopgo.io/coopgo-platform/emailing"
"github.com/spf13/viper"
)
type ApplicationHandler struct {
2022-10-31 23:40:20 +00:00
config *viper.Viper
Renderer *renderer.Renderer
services *services.ServicesHandler
cache cache.CacheHandler
filestorage cache.FileStorage
emailing *emailing.Mailer
}
2022-10-31 23:40:20 +00:00
func NewApplicationHandler(cfg *viper.Viper, svc *services.ServicesHandler, cache cache.CacheHandler, filestorage cache.FileStorage, emailing *emailing.Mailer) (*ApplicationHandler, error) {
templates_root := cfg.GetString("templates.root")
renderer := renderer.NewRenderer(cfg, templates_root)
return &ApplicationHandler{
2022-10-31 23:40:20 +00:00
config: cfg,
Renderer: renderer,
services: svc,
cache: cache,
filestorage: filestorage,
emailing: emailing,
}, nil
}
func (h *ApplicationHandler) NotFound(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusNotFound)
}
func (h *ApplicationHandler) templateFile(file string) string {
return h.config.GetString("templates.root") + file
}