package web import ( "net/http" "github.com/gorilla/context" ) type key int // dKey is key for access to response data in context const dKey key = 0 // GetAllData return response's data func GetAllData(r *http.Request) map[string]interface{} { data, ok := context.GetOk(r, dKey) 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, dKey) if !ok { context.Set(r, dKey, make(map[string]interface{})) data = make(map[string]interface{}) } data.(map[string]interface{})[key] = val context.Set(r, dKey, data) }