2022-08-11 15:26:55 +00:00
|
|
|
package application
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"git.coopgo.io/coopgo-apps/parcoursmob/renderer"
|
|
|
|
"git.coopgo.io/coopgo-apps/parcoursmob/services"
|
2022-10-30 19:11:36 +00:00
|
|
|
cache "git.coopgo.io/coopgo-apps/parcoursmob/utils/storage"
|
2022-10-17 03:02:19 +00:00
|
|
|
"git.coopgo.io/coopgo-platform/emailing"
|
2022-08-11 15:26:55 +00:00
|
|
|
"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-08-11 15:26:55 +00:00
|
|
|
}
|
|
|
|
|
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) {
|
2022-08-11 15:26:55 +00:00
|
|
|
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,
|
2022-08-11 15:26:55 +00:00
|
|
|
}, 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
|
|
|
|
}
|