42 lines
1.2 KiB
Go
42 lines
1.2 KiB
Go
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 {
|
|
config *viper.Viper
|
|
Renderer *renderer.Renderer
|
|
services *services.ServicesHandler
|
|
cache cache.CacheHandler
|
|
filestorage cache.FileStorage
|
|
emailing *emailing.Mailer
|
|
}
|
|
|
|
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{
|
|
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
|
|
}
|