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)))
|
router.Handle("/", m(controllers_pages.MainPageHandler(a)))
|
||||||
}
|
}
|
||||||
|
|
||||||
// api
|
|
||||||
{
|
|
||||||
router.Handle("/api/count/", m(controllers.CountHandler()))
|
|
||||||
}
|
|
||||||
|
|
||||||
return router
|
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
|
package controllers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"log"
|
||||||
"main/mvc/models"
|
"main/mvc/models"
|
||||||
models_pages "main/mvc/models/pages"
|
models_pages "main/mvc/models/pages"
|
||||||
|
"main/tools"
|
||||||
"net/http"
|
"net/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Обработчик главной страницы
|
// Обработчик главной страницы
|
||||||
func MainPageHandler(a *models.App) http.HandlerFunc {
|
func MainPageHandler(a *models.App) http.HandlerFunc {
|
||||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
var err error
|
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)
|
pageData, ok := a.Cache.Get(models_pages.MainPageTmplName)
|
||||||
if !ok {
|
if !ok {
|
||||||
|
@ -32,3 +45,10 @@ func SendMainPage(w http.ResponseWriter, data []byte) {
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
w.Write(data)
|
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>
|
</p>
|
||||||
<ul>
|
<ul>
|
||||||
<li>unix timestamp of page rendering - <strong>{{ .renderingTimestamp }}</strong></li>
|
<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>
|
<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>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in New Issue