examples/stream: Remove usage of Flusher

This commit is contained in:
Adnan Maolood 2021-02-22 20:07:15 -05:00
parent 118e019df0
commit c5b304216c

View File

@ -38,9 +38,7 @@ func main() {
defer wg.Wait() defer wg.Wait()
mux.HandleFunc("/shutdown", func(ctx context.Context, w gemini.ResponseWriter, r *gemini.Request) { mux.HandleFunc("/shutdown", func(ctx context.Context, w gemini.ResponseWriter, r *gemini.Request) {
fmt.Fprintln(w, "Shutting down...") fmt.Fprintln(w, "Shutting down...")
if flusher, ok := w.(gemini.Flusher); ok { w.Flush()
flusher.Flush()
}
go shutdownOnce.Do(func() { go shutdownOnce.Do(func() {
server.Shutdown(context.Background()) server.Shutdown(context.Background())
wg.Done() wg.Done()
@ -54,12 +52,6 @@ func main() {
// stream writes an infinite stream to w. // stream writes an infinite stream to w.
func stream(ctx context.Context, w gemini.ResponseWriter, r *gemini.Request) { func stream(ctx context.Context, w gemini.ResponseWriter, r *gemini.Request) {
flusher, ok := w.(gemini.Flusher)
if !ok {
w.WriteHeader(gemini.StatusTemporaryFailure, "Internal error")
return
}
ch := make(chan string) ch := make(chan string)
ctx, cancel := context.WithCancel(ctx) ctx, cancel := context.WithCancel(ctx)
@ -84,7 +76,7 @@ func stream(ctx context.Context, w gemini.ResponseWriter, r *gemini.Request) {
break break
} }
fmt.Fprintln(w, s) fmt.Fprintln(w, s)
if err := flusher.Flush(); err != nil { if err := w.Flush(); err != nil {
cancel() cancel()
return return
} }