aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorAdnan Maolood <[email protected]>2021-02-22 20:07:15 -0500
committerAdnan Maolood <[email protected]>2021-02-22 20:07:37 -0500
commitc5b304216c7c22bcf7ed19b792209d3cd8651e28 (patch)
treed5b6dfc80b371471152b9cc270f13e4d9cb1e8b2 /examples
parentserver: Use channel to communicate shutdown (diff)
downloadarchived-go-gemini-c5b304216c7c22bcf7ed19b792209d3cd8651e28.tar.xz
archived-go-gemini-c5b304216c7c22bcf7ed19b792209d3cd8651e28.zip
examples/stream: Remove usage of Flusher
Diffstat (limited to 'examples')
-rw-r--r--examples/stream.go12
1 files changed, 2 insertions, 10 deletions
diff --git a/examples/stream.go b/examples/stream.go
index f64f87b..f4cbf09 100644
--- a/examples/stream.go
+++ b/examples/stream.go
@@ -38,9 +38,7 @@ func main() {
defer wg.Wait()
mux.HandleFunc("/shutdown", func(ctx context.Context, w gemini.ResponseWriter, r *gemini.Request) {
fmt.Fprintln(w, "Shutting down...")
- if flusher, ok := w.(gemini.Flusher); ok {
- flusher.Flush()
- }
+ w.Flush()
go shutdownOnce.Do(func() {
server.Shutdown(context.Background())
wg.Done()
@@ -54,12 +52,6 @@ func main() {
// stream writes an infinite stream to w.
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)
ctx, cancel := context.WithCancel(ctx)
@@ -84,7 +76,7 @@ func stream(ctx context.Context, w gemini.ResponseWriter, r *gemini.Request) {
break
}
fmt.Fprintln(w, s)
- if err := flusher.Flush(); err != nil {
+ if err := w.Flush(); err != nil {
cancel()
return
}