package controllers import ( "main/mvc/models" models_pages "main/mvc/models/pages" "net/http" ) // Обработчик главной страницы func MainRuPageHandler(a *models.App) http.HandlerFunc { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { var err error // Страничка рендерится только если ее нет в кэше pageData, ok := a.Cache.Get(models_pages.MainRuPageTmplName) if !ok { pageData, err = models_pages.RenderMainRuPage(a.Templates, a.Version) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return } a.Cache.Set(models_pages.MainRuPageTmplName, pageData) } SendMainPage(w, pageData.([]byte)) }) } // Отправляет страницу func SendMainRuPage(w http.ResponseWriter, data []byte) { w.Header().Set("Content-Type", "text/html; charset=utf-8") w.WriteHeader(http.StatusOK) w.Write(data) }