see if http.Flush works

This commit is contained in:
Jeff Carr 2024-11-28 00:03:36 -06:00
parent fe562dbf1b
commit 9b12c5049e
1 changed files with 27 additions and 2 deletions

View File

@ -8,6 +8,7 @@ import (
"io"
reallog "log"
"net/http"
"time"
)
func DaemonMode(b bool) {
@ -20,8 +21,21 @@ func CaptureMode(w io.Writer) {
captureMode = w
}
var flusher http.Flusher
func HttpMode(w http.ResponseWriter) {
var ok bool
httpMode = w
if w == nil {
flusher = nil
return
}
flusher, ok = w.(http.Flusher)
if !ok {
http.Error(w, "Streaming unsupported!", http.StatusInternalServerError)
flusher = nil
return
}
}
func DaemonShow() bool {
@ -52,8 +66,13 @@ func realPrintln(a ...any) {
}
}
if httpMode != nil {
s := fmt.Sprint(a...)
now := time.Now()
timestamp := now.Format("2006/01/02 15:04:05") // bummer. other date doesn't work?
s := timestamp + " " + fmt.Sprint(a...)
fmt.Fprintln(httpMode, s)
if flusher != nil {
flusher.Flush() // Flush the data to the client
}
}
}
@ -74,7 +93,13 @@ func realPrintf(s string, a ...any) {
}
}
if httpMode != nil {
fmt.Fprintln(httpMode, fmt.Sprintf(s, a...))
now := time.Now()
timestamp := now.Format("2006/01/02 15:04:05") // bummer. other date doesn't work?
s := timestamp + " " + fmt.Sprintf(s, a...)
fmt.Fprintln(httpMode, s)
if flusher != nil {
flusher.Flush() // Flush the data to the client
}
}
}