Added streaming

This commit is contained in:
2024-03-22 14:37:21 +01:00
parent 1803bf7108
commit 17158235ea
3 changed files with 46 additions and 0 deletions

28
examples/stream/main.go Normal file
View 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")
}