package mid import ( "fmt" "net/http" "github.com/justinas/nosurf" ) func NoSurf(next http.Handler) http.Handler { return nosurf.New(next) } func NoSurfContext(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { token := nosurf.Token(r) ctx := setCsrfToken(r.Context(), token) ctx = setHtmlCsrfToken(ctx, fmt.Sprintf(``, token)) next.ServeHTTP(w, r.WithContext(ctx)) }) }