// Serve an HTTP request. func (pe *ProvideEnv) ServeHTTP(w http.ResponseWriter, r *http.Request) { handlers.SetRequestEnv(r, pe.env) pe.handler.ServeHTTP(w, r) // we don't need to call context.Clear(r) or context.ClearHandler() // because the gorilla mux router does it automatically after each request }
// Serve an HTTP request. func (ir *IncludeRelated) ServeHTTP(w http.ResponseWriter, r *http.Request) { // retrieve route parameters env := handlers.GetRequestEnv(r) include := r.URL.Query().Get("include") // check if any resources should be included query := env.DB if len(include) > 0 { // preload related models resources := strings.Split(include, ",") for _, resource := range resources { query = query.Preload(Capitalize(resource)) } // update the environment handlers.SetRequestEnv(r, handlers.NewEnv(query)) } // run the original handler ir.handler.ServeHTTP(w, r) }