package web import ( "net/http" "github.com/gorilla/context" ) type contextKey int // RespData is key for access to response data in context const respData contextKey = 0 // GetAllData return response's data func GetAllData(r *http.Request) map[string]interface{} { data, ok := context.GetOk(r, respData) if !ok { return nil } d, ok := data.(map[string]interface{}) if !ok { return nil } return d } // SetData sets some response's data for access in template func SetData(r *http.Request, key string, val interface{}) { data, ok := context.GetOk(r, respData) if !ok { context.Set(r, respData, make(map[string]interface{})) data = make(map[string]interface{}) } data.(map[string]interface{})[key] = val context.Set(r, respData, data) }