diff --git a/main.go b/main.go index d904343..919fee8 100644 --- a/main.go +++ b/main.go @@ -68,11 +68,6 @@ func setupRoutes(a *models.App) *http.ServeMux { router.Handle("/", m(controllers_pages.MainPageHandler(a))) } - // api - { - router.Handle("/api/count/", m(controllers.CountHandler())) - } - return router } diff --git a/mvc/controllers/api.go b/mvc/controllers/api.go deleted file mode 100644 index 7a7b5bb..0000000 --- a/mvc/controllers/api.go +++ /dev/null @@ -1,24 +0,0 @@ -package controllers - -import ( - "log" - "main/tools" - "net/http" -) - -func CountHandler() http.HandlerFunc { - return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - var count []byte - var err error - if count, err = tools.GetJournalctlLogs("server", "hikan.ru", 24); err != nil { - log.Printf("%s", err.Error()) - } - SendCount(w, count) - }) -} - -func SendCount(w http.ResponseWriter, data []byte) { - w.Header().Set("Content-Type", "text/plain; charset=utf-8") - w.WriteHeader(http.StatusOK) - w.Write(data) -} diff --git a/mvc/controllers/pages/main.go b/mvc/controllers/pages/main.go index 6fc27dd..99c7d55 100644 --- a/mvc/controllers/pages/main.go +++ b/mvc/controllers/pages/main.go @@ -1,16 +1,29 @@ package controllers import ( + "log" "main/mvc/models" models_pages "main/mvc/models/pages" + "main/tools" "net/http" ) // Обработчик главной страницы func MainPageHandler(a *models.App) http.HandlerFunc { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + var err error + // Количество запросов, обработанных сервером за 24ч + if r.Method == "COUNT" { + var count []byte + if count, err = tools.GetJournalctlLogs("server", "hikan.ru", 24); err != nil { + log.Printf("%s", err.Error()) + } + SendCount(w, count) + return + } + // Страничка рендерится только если ее нет в кэше pageData, ok := a.Cache.Get(models_pages.MainPageTmplName) if !ok { @@ -32,3 +45,10 @@ func SendMainPage(w http.ResponseWriter, data []byte) { w.WriteHeader(http.StatusOK) w.Write(data) } + +// Ответ на метод COUNT +func SendCount(w http.ResponseWriter, data []byte) { + w.Header().Set("Content-Type", "text/plain; charset=utf-8") + w.WriteHeader(http.StatusOK) + w.Write(data) +} diff --git a/mvc/views/pages/main.gohtml b/mvc/views/pages/main.gohtml index a3ae1d8..6452092 100644 --- a/mvc/views/pages/main.gohtml +++ b/mvc/views/pages/main.gohtml @@ -107,6 +107,7 @@