0
0
mirror of https://github.com/rls-moe/nyx synced 2024-11-22 22:12:24 +00:00
nyx/http/middle/base.go
2017-03-13 16:04:00 +01:00

31 lines
555 B
Go

package middle
import (
"github.com/justinas/nosurf"
"github.com/pressly/chi/middleware"
"net/http"
)
func GetBaseCtx(r *http.Request) map[string]interface{} {
val := map[string]interface{}{
"Config": GetConfig(r),
"ReqID": middleware.GetReqID(r.Context()),
"CSRFToken": nosurf.Token(r),
}
if sess := GetSession(r); sess != nil {
val["Session"] = sess
}
err := r.URL.Query().Get("err")
if err != "" {
val["PreviousError"] = err
}
return val
}
func CSRFProtect(next http.Handler) http.Handler {
return nosurf.New(next)
}