Esempio n. 1
0
func GetData(req *http.Request) map[string]interface{} {
	if rv := context.Get(req, datakey); rv != nil {
		// 获取之后立马删除
		context.Delete(req, datakey)
		return rv.(map[string]interface{})
	}
	return make(map[string]interface{})
}
Esempio n. 2
0
func getData(req *http.Request, viewkey viewKey) interface{} {
	if rv := context.Get(req, viewkey); rv != nil {
		// 获取之后立马删除
		context.Delete(req, viewkey)
		return rv
	}
	return nil
}
Esempio n. 3
0
func (p *renderSetupHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
	r.ParseForm()

	renderEngine := render.New(render.Options{
		IndentJSON: (r.Form.Get("pretty") == "true"),
	})

	context.Set(r, renderContextKey, renderEngine)
	defer context.Delete(r, renderContextKey)

	p.next.ServeHTTP(w, r)
}
Esempio n. 4
0
// CsrfMiddleware adds CSRF support via nosurf.
func CsrfMiddleware(w http.ResponseWriter, r *http.Request, next http.HandlerFunc) {
	var token string
	var passed bool

	// nosurf disposes of the token as soon as it calls the http.Handler you provide...
	// in order to use it as negroni middleware, pull out token and dispose of it ourselves
	csrfHandler := nosurf.NewPure(http.HandlerFunc(func(http.ResponseWriter, *http.Request) {
		token = nosurf.Token(r)
		passed = true
	}))
	csrfHandler.ServeHTTP(w, r)

	// csrf passed
	if passed {
		context.Set(r, "csrf_token", token)
		next(w, r)
		context.Delete(r, "csrf_token")
	}
}
Esempio n. 5
0
func (this *CookieFilter) PostFilter(rw http.ResponseWriter, req *http.Request) bool {
	// 删除设置的用户信息
	context.Delete(req, userkey)
	return true
}
func (cua *CurrentUserAccessor) Clear(r *http.Request) {
	context.Delete(r, cua.key)
}