Added streaming

This commit is contained in:
Eduard Urbach 2024-03-22 14:37:21 +01:00
parent fff5ce19b8
commit ce209e79ed
Signed by: eduard
GPG key ID: 49226B848C78F6C8
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")
}