pcmt/app/echoSettings.go
leo 72723d951d
All checks were successful
continuous-integration/drone/push Build is passing
go(refactor): clean up run.go
2023-05-17 20:40:24 +02:00

71 lines
1.8 KiB
Go

package app
import (
"net/http"
"github.com/gorilla/sessions"
"github.com/labstack/echo-contrib/session"
"github.com/labstack/echo/v4/middleware"
)
func (a *App) SetEchoSettings() {
e := a.E()
e.HideBanner = true
e.Use(middleware.Logger())
// e.Use(middleware.LoggerWithConfig(
// middleware.LoggerConfig{
// Format: `{"time":"${time_rfc3339_nano}","id":"${id}","remote_ip":"${remote_ip}",` +
// `"host":"${host}","method":"${method}","uri":"${uri}","user_agent":"${user_agent}",` +
// `"status":${status},"error":"${error}","latency":${latency},"latency_human":"${latency_human}"` +
// `,"bytes_in":${bytes_in},"bytes_out":${bytes_out}}` + "\n",
// CustomTimeFormat: "2006-01-02 15:04:05.00000",
// },
// ))
// logger := zerolog.New(os.Stdout)
// e.Use(middleware.RequestLoggerWithConfig(middleware.RequestLoggerConfig{
// LogURI: true,
// LogStatus: true,
// LogValuesFunc: func(c echo.Context, v middleware.RequestLoggerValues) error {
// logger.Info().
// Str("URI", v.URI).
// Int("status", v.Status).
// Msg("request")
//
// return nil
// },
// }))
// TODO: have this in the config.
e.Use(middleware.RateLimiter(middleware.NewRateLimiterMemoryStore(20)))
// TODO: add check for prometheus config setting.
// if true {
// // import "github.com/labstack/echo-contrib/prometheus"
// p := prometheus.NewPrometheus("echo", nil)
// p.Use(e)
// }
e.Use(middleware.Recover())
e.Use(session.Middleware(
sessions.NewCookieStore(
[]byte(a.setting.SessionCookieSecret()),
),
))
// e.Use(middleware.CSRF())
e.Use(middleware.CSRFWithConfig(middleware.CSRFConfig{
TokenLookup: "cookie:_csrf",
CookiePath: "/",
// CookieDomain: "example.com",
// CookieSecure: true,
CookieHTTPOnly: true,
CookieSameSite: http.SameSiteStrictMode,
}),
)
e.Use(middleware.Secure())
}