File tree 1 file changed +18
-18
lines changed
examples/streaming-http-servers
1 file changed +18
-18
lines changed Original file line number Diff line number Diff line change 1
1
package main
2
2
3
3
import (
4
- "fmt"
5
- "net/http"
6
- "time"
4
+ "fmt"
5
+ "net/http"
6
+ "time"
7
7
)
8
8
9
9
func stream (resp http.ResponseWriter , req * http.Request ) {
10
- respf , ok := resp .(http.Flusher )
11
- if ! ok {
12
- panic ("not flushable" )
13
- }
14
- fmt .Println ("stream" )
15
- resp .WriteHeader (200 )
16
- for i := 0 ; i < 10 ; i ++ {
17
- n , err := resp .Write ([]byte ("tick\n " ))
18
- respf .Flush ()
19
- fmt .Println ("tick" , n , err )
20
- time .Sleep (time .Second * 1 )
21
- }
10
+ respf , ok := resp .(http.Flusher )
11
+ if ! ok {
12
+ panic ("not flushable" )
13
+ }
14
+ fmt .Println ("stream" )
15
+ resp .WriteHeader (200 )
16
+ for i := 0 ; i < 10 ; i ++ {
17
+ n , err := resp .Write ([]byte ("tick\n " ))
18
+ respf .Flush ()
19
+ fmt .Println ("tick" , n , err )
20
+ time .Sleep (time .Second * 1 )
21
+ }
22
22
}
23
23
24
24
func main () {
25
- http .HandleFunc ("/" , stream )
26
- fmt .Println ("serve" )
27
- http .ListenAndServe (":5000" , nil )
25
+ http .HandleFunc ("/" , stream )
26
+ fmt .Println ("serve" )
27
+ http .ListenAndServe (":5000" , nil )
28
28
}
You can’t perform that action at this time.
0 commit comments