Added streaming
This commit is contained in:
28
examples/stream/main.go
Normal file
28
examples/stream/main.go
Normal file
@ -0,0 +1,28 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"git.akyoto.dev/go/server"
|
||||
)
|
||||
|
||||
func main() {
|
||||
s := server.New()
|
||||
|
||||
s.Get("/", func(ctx server.Context) error {
|
||||
ticker := time.NewTicker(time.Second)
|
||||
|
||||
for {
|
||||
select {
|
||||
case <-ctx.Request().Context().Done():
|
||||
return nil
|
||||
|
||||
case <-ticker.C:
|
||||
ctx.Response().WriteString("Hello\n")
|
||||
ctx.Response().Flush()
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
s.Run(":8080")
|
||||
}
|
Reference in New Issue
Block a user