some changes
parent
3d6aca38b4
commit
b81ce295c6
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue