some changes
parent
4fee94002c
commit
4f4e58341f
5
main.go
5
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
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
}
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -107,6 +107,7 @@
|
|||
</p>
|
||||
<ul>
|
||||
<li>unix timestamp of page rendering - <strong>{{ .renderingTimestamp }}</strong></li>
|
||||
<li><code>curl -X COUNT https://hikan.ru/</code> - 24-hour server request count</li>
|
||||
<li>this site code repository - <a href="https://git.hikan.ru/serr/hikan.ru" target="_blank">git.hikan.ru/serr/hikan.ru</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
|
Loading…
Reference in New Issue