From 9fe73a6962daa29c5242499ef3fb8bed55946116 Mon Sep 17 00:00:00 2001 From: Chetan Sarva Date: Wed, 3 Nov 2021 14:33:53 -0400 Subject: [PATCH] cleanup: replace deprecated CloseNotifier with ctx --- daemon.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/daemon.go b/daemon.go index 10176c3..044ee13 100644 --- a/daemon.go +++ b/daemon.go @@ -1,6 +1,7 @@ package vproxy import ( + "context" "fmt" "log" "net" @@ -211,15 +212,14 @@ func (d *Daemon) streamLogs(w http.ResponseWriter, r *http.Request) { } // runs forever until connection closes - d.relayLogsUntilClose(flusher, logChan, rw, w) + d.relayLogsUntilClose(flusher, logChan, w, r.Context()) } -func (d *Daemon) relayLogsUntilClose(flusher http.Flusher, logChan chan string, rw http.ResponseWriter, w http.ResponseWriter) { +func (d *Daemon) relayLogsUntilClose(flusher http.Flusher, logChan chan string, w http.ResponseWriter, reqCtx context.Context) { // Listen to connection close and un-register logChan - notify := rw.(http.CloseNotifier).CloseNotify() for { select { - case <-notify: + case <-reqCtx.Done(): return case line := <-logChan: fmt.Fprintln(w, line)