Last active
March 2, 2019 11:33
-
-
Save marconi/fbd85020678a0cd9cf973d7bf79e30c6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To run:
$ go run main.go