gofmt
This commit is contained in:
parent
c6b39fbc72
commit
8fa1292ae5
@ -1,28 +1,28 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func stream(resp http.ResponseWriter, req *http.Request) {
|
func stream(resp http.ResponseWriter, req *http.Request) {
|
||||||
respf, ok := resp.(http.Flusher)
|
respf, ok := resp.(http.Flusher)
|
||||||
if !ok {
|
if !ok {
|
||||||
panic("not flushable")
|
panic("not flushable")
|
||||||
}
|
}
|
||||||
fmt.Println("stream")
|
fmt.Println("stream")
|
||||||
resp.WriteHeader(200)
|
resp.WriteHeader(200)
|
||||||
for i := 0; i < 10; i++ {
|
for i := 0; i < 10; i++ {
|
||||||
n, err := resp.Write([]byte("tick\n"))
|
n, err := resp.Write([]byte("tick\n"))
|
||||||
respf.Flush()
|
respf.Flush()
|
||||||
fmt.Println("tick", n, err)
|
fmt.Println("tick", n, err)
|
||||||
time.Sleep(time.Second * 1)
|
time.Sleep(time.Second * 1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
http.HandleFunc("/", stream)
|
http.HandleFunc("/", stream)
|
||||||
fmt.Println("serve")
|
fmt.Println("serve")
|
||||||
http.ListenAndServe(":5000", nil)
|
http.ListenAndServe(":5000", nil)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user