Skip to content

Instantly share code, notes, and snippets.

@marconi
Last active March 2, 2019 11:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marconi/fbd85020678a0cd9cf973d7bf79e30c6 to your computer and use it in GitHub Desktop.
Save marconi/fbd85020678a0cd9cf973d7bf79e30c6 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"log"
"net/http"
"time"
)
func main() {
http.HandleFunc("/test", func(w http.ResponseWriter, r *http.Request) {
w.Header().Add("Access-Control-Allow-Origin", "*")
flusher, ok := w.(http.Flusher)
if !ok {
http.Error(w, "Something went wrong.", http.StatusInternalServerError)
return
}
for i := 1; ; i++ {
fmt.Fprintf(w, "Chunk #%d\n", i)
flusher.Flush()
time.Sleep(500 * time.Millisecond)
}
})
log.Fatalln(http.ListenAndServe("localhost:8080", nil))
}
@marconi
Copy link
Author

marconi commented Mar 2, 2019

To run: $ go run main.go

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment