From b81ce295c674656deeb4302d2ca817896769face Mon Sep 17 00:00:00 2001 From: serr Date: Sun, 6 Apr 2025 18:26:02 +0300 Subject: [PATCH] some changes --- mvc/controllers/pages/main.go | 27 +++------------------------ tools/logs.go | 2 +- 2 files changed, 4 insertions(+), 25 deletions(-) diff --git a/mvc/controllers/pages/main.go b/mvc/controllers/pages/main.go index 700ffb7..5d29f17 100644 --- a/mvc/controllers/pages/main.go +++ b/mvc/controllers/pages/main.go @@ -6,8 +6,6 @@ import ( models_pages "main/mvc/models/pages" "main/tools" "net/http" - "time" - "unicode/utf8" ) // Обработчик главной страницы @@ -71,33 +69,14 @@ func SendCount(w http.ResponseWriter, data []byte) { func SendLove(w http.ResponseWriter) { w.Header().Set("Content-Type", "text/plain; charset=utf-8") w.WriteHeader(http.StatusOK) - w.Write([]byte("13.01.2005")) + w.Write([]byte("13.01.2005\n")) } // Ответ на метод LIMINAL func SendLiminal(w http.ResponseWriter) { w.Header().Set("Content-Type", "text/plain; charset=utf-8") - w.Header().Set("X-Accel-Buffering", "no") // важно для nginx w.WriteHeader(http.StatusOK) + text := "If you're not careful and you slip out of reality in the wrong place, you'll end up in the Backstage, where there's nothing but the stench of old damp carpet, yellow-colored madness, the endless unbearable hum of fluorescent lights, and roughly six hundred million square miles of randomly arranged empty rooms.\n" + w.Write([]byte(text)) - text := "If you're not careful and you slip out of reality in the wrong place, you'll end up in the Backstage, where there's nothing but the stench of old damp carpet, yellow-colored madness, the endless unbearable hum of fluorescent lights, and roughly six hundred million square miles of randomly arranged empty rooms." - - flusher, ok := w.(http.Flusher) - if !ok { - w.Write([]byte(text)) - return - } - - // Корректно работает с любыми UTF-8 символами! - buf := make([]byte, 4) // Максимальный размер руны - 4 байта - for _, char := range text { - n := utf8.EncodeRune(buf, char) // руну байтами записываем в buf - if _, err := w.Write(buf[:n]); err != nil { // [:n] потому что руной заняты только столько байт, сколько вернула EncodeRune - return - } - if flusher != nil { - flusher.Flush() - } - time.Sleep(50 * time.Millisecond) - } } diff --git a/tools/logs.go b/tools/logs.go index 5e5bd8c..903758e 100644 --- a/tools/logs.go +++ b/tools/logs.go @@ -25,5 +25,5 @@ func GetJournalctlLogs(serviceName, grepPattern string, hoursAgo int) ([]byte, e return nil, err } - return bytes.TrimSpace(output.Bytes()), nil + return output.Bytes(), nil }