37 lines
971 B
Go
37 lines
971 B
Go
package application
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"git.coopgo.io/coopgo-apps/parcoursmob/renderer"
|
|
"git.coopgo.io/coopgo-apps/parcoursmob/services"
|
|
"git.coopgo.io/coopgo-apps/parcoursmob/utils/cache"
|
|
"github.com/spf13/viper"
|
|
)
|
|
|
|
type ApplicationHandler struct {
|
|
config *viper.Viper
|
|
Renderer *renderer.Renderer
|
|
services *services.ServicesHandler
|
|
cache *cache.CacheHandler
|
|
}
|
|
|
|
func NewApplicationHandler(cfg *viper.Viper, svc *services.ServicesHandler, cache *cache.CacheHandler) (*ApplicationHandler, error) {
|
|
templates_root := cfg.GetString("templates.root")
|
|
renderer := renderer.NewRenderer(cfg, templates_root)
|
|
return &ApplicationHandler{
|
|
config: cfg,
|
|
Renderer: renderer,
|
|
services: svc,
|
|
cache: cache,
|
|
}, 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
|
|
}
|