mirror of
https://github.com/gofiber/fiber.git
synced 2025-05-31 11:52:41 +00:00
docs: add SSE example (#1776)
This commit is contained in:
parent
daab00c36e
commit
e1833df93c
42
.github/README.md
vendored
42
.github/README.md
vendored
@ -133,6 +133,7 @@ go get -u github.com/gofiber/fiber/v2
|
|||||||
- [Rapid](https://dev.to/koddr/welcome-to-fiber-an-express-js-styled-fastest-web-framework-written-with-on-golang-497) server-side programming
|
- [Rapid](https://dev.to/koddr/welcome-to-fiber-an-express-js-styled-fastest-web-framework-written-with-on-golang-497) server-side programming
|
||||||
- [Template engines](https://github.com/gofiber/template)
|
- [Template engines](https://github.com/gofiber/template)
|
||||||
- [WebSocket support](https://github.com/gofiber/websocket)
|
- [WebSocket support](https://github.com/gofiber/websocket)
|
||||||
|
- [Server-Sent events](https://github.com/gofiber/recipes/tree/master/sse)
|
||||||
- [Rate Limiter](https://docs.gofiber.io/api/middleware/limiter)
|
- [Rate Limiter](https://docs.gofiber.io/api/middleware/limiter)
|
||||||
- Translated in [15 languages](https://docs.gofiber.io/)
|
- Translated in [15 languages](https://docs.gofiber.io/)
|
||||||
- And much more, [explore Fiber](https://docs.gofiber.io/)
|
- And much more, [explore Fiber](https://docs.gofiber.io/)
|
||||||
@ -497,6 +498,47 @@ func main() {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Server-Sent Events
|
||||||
|
|
||||||
|
📖 [More Info](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events)
|
||||||
|
|
||||||
|
```go
|
||||||
|
import (
|
||||||
|
"github.com/gofiber/fiber/v2"
|
||||||
|
"github.com/valyala/fasthttp"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
app := fiber.New()
|
||||||
|
|
||||||
|
app.Get("/sse", func(c *fiber.Ctx) error {
|
||||||
|
c.Set("Content-Type", "text/event-stream")
|
||||||
|
c.Set("Cache-Control", "no-cache")
|
||||||
|
c.Set("Connection", "keep-alive")
|
||||||
|
c.Set("Transfer-Encoding", "chunked")
|
||||||
|
|
||||||
|
c.Context().SetBodyStreamWriter(fasthttp.StreamWriter(func(w *bufio.Writer) {
|
||||||
|
fmt.Println("WRITER")
|
||||||
|
var i int
|
||||||
|
|
||||||
|
for {
|
||||||
|
i++
|
||||||
|
msg := fmt.Sprintf("%d - the time is %v", i, time.Now())
|
||||||
|
fmt.Fprintf(w, "data: Message: %s\n\n", msg)
|
||||||
|
fmt.Println(msg)
|
||||||
|
|
||||||
|
w.Flush()
|
||||||
|
time.Sleep(5 * time.Second)
|
||||||
|
}
|
||||||
|
}))
|
||||||
|
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
|
||||||
|
log.Fatal(app.Listen(":3000"))
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
### Recover middleware
|
### Recover middleware
|
||||||
|
|
||||||
📖 [Recover](https://docs.gofiber.io/api/middleware/recover)
|
📖 [Recover](https://docs.gofiber.io/api/middleware/recover)
|
||||||
|
42
.github/README_ckb.md
vendored
42
.github/README_ckb.md
vendored
@ -130,6 +130,7 @@ go get -u github.com/gofiber/fiber/v2
|
|||||||
- پڕۆگرامکردنی [خێرا](https://dev.to/koddr/welcome-to-fiber-an-express-js-styled-fastest-web-framework-written-with-on-golang-497)ی ڕاژە
|
- پڕۆگرامکردنی [خێرا](https://dev.to/koddr/welcome-to-fiber-an-express-js-styled-fastest-web-framework-written-with-on-golang-497)ی ڕاژە
|
||||||
- [داڕێژە](https://github.com/gofiber/template)
|
- [داڕێژە](https://github.com/gofiber/template)
|
||||||
- پشتگیریی [WebSocket](https://github.com/gofiber/websocket)
|
- پشتگیریی [WebSocket](https://github.com/gofiber/websocket)
|
||||||
|
- [Server-Sent events](https://github.com/gofiber/recipes/tree/master/sse)
|
||||||
- [Rate Limiter](https://docs.gofiber.io/api/middleware/limiter)
|
- [Rate Limiter](https://docs.gofiber.io/api/middleware/limiter)
|
||||||
- وەرگێڕراوە بۆ [15 زمان](https://docs.gofiber.io/)
|
- وەرگێڕراوە بۆ [15 زمان](https://docs.gofiber.io/)
|
||||||
- زیاتریش، [فایبەر بپشکنە](https://docs.gofiber.io/)
|
- زیاتریش، [فایبەر بپشکنە](https://docs.gofiber.io/)
|
||||||
@ -497,6 +498,47 @@ func main() {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Server-Sent Events
|
||||||
|
|
||||||
|
📖 [More Info](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events)
|
||||||
|
|
||||||
|
```go
|
||||||
|
import (
|
||||||
|
"github.com/gofiber/fiber/v2"
|
||||||
|
"github.com/valyala/fasthttp"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
app := fiber.New()
|
||||||
|
|
||||||
|
app.Get("/sse", func(c *fiber.Ctx) error {
|
||||||
|
c.Set("Content-Type", "text/event-stream")
|
||||||
|
c.Set("Cache-Control", "no-cache")
|
||||||
|
c.Set("Connection", "keep-alive")
|
||||||
|
c.Set("Transfer-Encoding", "chunked")
|
||||||
|
|
||||||
|
c.Context().SetBodyStreamWriter(fasthttp.StreamWriter(func(w *bufio.Writer) {
|
||||||
|
fmt.Println("WRITER")
|
||||||
|
var i int
|
||||||
|
|
||||||
|
for {
|
||||||
|
i++
|
||||||
|
msg := fmt.Sprintf("%d - the time is %v", i, time.Now())
|
||||||
|
fmt.Fprintf(w, "data: Message: %s\n\n", msg)
|
||||||
|
fmt.Println(msg)
|
||||||
|
|
||||||
|
w.Flush()
|
||||||
|
time.Sleep(5 * time.Second)
|
||||||
|
}
|
||||||
|
}))
|
||||||
|
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
|
||||||
|
log.Fatal(app.Listen(":3000"))
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
### Recover middleware
|
### Recover middleware
|
||||||
|
|
||||||
📖 [Recover](https://docs.gofiber.io/api/middleware/recover)
|
📖 [Recover](https://docs.gofiber.io/api/middleware/recover)
|
||||||
|
42
.github/README_de.md
vendored
42
.github/README_de.md
vendored
@ -130,6 +130,7 @@ go get -u github.com/gofiber/fiber/v2
|
|||||||
- [Schnelle](https://dev.to/koddr/welcome-to-fiber-an-express-js-styled-fastest-web-framework-written-with-on-golang-497) serverseitige Programmierung
|
- [Schnelle](https://dev.to/koddr/welcome-to-fiber-an-express-js-styled-fastest-web-framework-written-with-on-golang-497) serverseitige Programmierung
|
||||||
- [Template engines](https://github.com/gofiber/template)
|
- [Template engines](https://github.com/gofiber/template)
|
||||||
- [WebSocket support](https://github.com/gofiber/websocket)
|
- [WebSocket support](https://github.com/gofiber/websocket)
|
||||||
|
- [Server-Sent events](https://github.com/gofiber/recipes/tree/master/sse)
|
||||||
- [Rate Limiter](https://docs.gofiber.io/api/middleware/limiter)
|
- [Rate Limiter](https://docs.gofiber.io/api/middleware/limiter)
|
||||||
- Verfügbar in [15 Sprachen](https://docs.gofiber.io/)
|
- Verfügbar in [15 Sprachen](https://docs.gofiber.io/)
|
||||||
- Und vieles mehr - [erkunde Fiber](https://docs.gofiber.io/)
|
- Und vieles mehr - [erkunde Fiber](https://docs.gofiber.io/)
|
||||||
@ -492,6 +493,47 @@ func main() {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Server-Sent Events
|
||||||
|
|
||||||
|
📖 [More Info](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events)
|
||||||
|
|
||||||
|
```go
|
||||||
|
import (
|
||||||
|
"github.com/gofiber/fiber/v2"
|
||||||
|
"github.com/valyala/fasthttp"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
app := fiber.New()
|
||||||
|
|
||||||
|
app.Get("/sse", func(c *fiber.Ctx) error {
|
||||||
|
c.Set("Content-Type", "text/event-stream")
|
||||||
|
c.Set("Cache-Control", "no-cache")
|
||||||
|
c.Set("Connection", "keep-alive")
|
||||||
|
c.Set("Transfer-Encoding", "chunked")
|
||||||
|
|
||||||
|
c.Context().SetBodyStreamWriter(fasthttp.StreamWriter(func(w *bufio.Writer) {
|
||||||
|
fmt.Println("WRITER")
|
||||||
|
var i int
|
||||||
|
|
||||||
|
for {
|
||||||
|
i++
|
||||||
|
msg := fmt.Sprintf("%d - the time is %v", i, time.Now())
|
||||||
|
fmt.Fprintf(w, "data: Message: %s\n\n", msg)
|
||||||
|
fmt.Println(msg)
|
||||||
|
|
||||||
|
w.Flush()
|
||||||
|
time.Sleep(5 * time.Second)
|
||||||
|
}
|
||||||
|
}))
|
||||||
|
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
|
||||||
|
log.Fatal(app.Listen(":3000"))
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
### Recover middleware
|
### Recover middleware
|
||||||
|
|
||||||
📖 [Recover](https://docs.gofiber.io/api/middleware/recover)
|
📖 [Recover](https://docs.gofiber.io/api/middleware/recover)
|
||||||
|
42
.github/README_es.md
vendored
42
.github/README_es.md
vendored
@ -130,6 +130,7 @@ go get -u github.com/gofiber/fiber/v2
|
|||||||
- Programación [rápida](https://dev.to/koddr/welcome-to-fiber-an-express-js-styled-fastest-web-framework-written-with-on-golang-497) del lado del servidor
|
- Programación [rápida](https://dev.to/koddr/welcome-to-fiber-an-express-js-styled-fastest-web-framework-written-with-on-golang-497) del lado del servidor
|
||||||
- [Template engines](https://github.com/gofiber/template)
|
- [Template engines](https://github.com/gofiber/template)
|
||||||
- [WebSocket support](https://github.com/gofiber/websocket)
|
- [WebSocket support](https://github.com/gofiber/websocket)
|
||||||
|
- [Server-Sent events](https://github.com/gofiber/recipes/tree/master/sse)
|
||||||
- [Rate Limiter](https://docs.gofiber.io/api/middleware/limiter)
|
- [Rate Limiter](https://docs.gofiber.io/api/middleware/limiter)
|
||||||
- Disponible en [15 idiomas](https://docs.gofiber.io/)
|
- Disponible en [15 idiomas](https://docs.gofiber.io/)
|
||||||
- Y mucho más, [explora Fiber](https://docs.gofiber.io/)
|
- Y mucho más, [explora Fiber](https://docs.gofiber.io/)
|
||||||
@ -492,6 +493,47 @@ func main() {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Server-Sent Events
|
||||||
|
|
||||||
|
📖 [More Info](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events)
|
||||||
|
|
||||||
|
```go
|
||||||
|
import (
|
||||||
|
"github.com/gofiber/fiber/v2"
|
||||||
|
"github.com/valyala/fasthttp"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
app := fiber.New()
|
||||||
|
|
||||||
|
app.Get("/sse", func(c *fiber.Ctx) error {
|
||||||
|
c.Set("Content-Type", "text/event-stream")
|
||||||
|
c.Set("Cache-Control", "no-cache")
|
||||||
|
c.Set("Connection", "keep-alive")
|
||||||
|
c.Set("Transfer-Encoding", "chunked")
|
||||||
|
|
||||||
|
c.Context().SetBodyStreamWriter(fasthttp.StreamWriter(func(w *bufio.Writer) {
|
||||||
|
fmt.Println("WRITER")
|
||||||
|
var i int
|
||||||
|
|
||||||
|
for {
|
||||||
|
i++
|
||||||
|
msg := fmt.Sprintf("%d - the time is %v", i, time.Now())
|
||||||
|
fmt.Fprintf(w, "data: Message: %s\n\n", msg)
|
||||||
|
fmt.Println(msg)
|
||||||
|
|
||||||
|
w.Flush()
|
||||||
|
time.Sleep(5 * time.Second)
|
||||||
|
}
|
||||||
|
}))
|
||||||
|
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
|
||||||
|
log.Fatal(app.Listen(":3000"))
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
### Middleware de Recuperación
|
### Middleware de Recuperación
|
||||||
|
|
||||||
📖 [Recover](https://docs.gofiber.io/api/middleware/recover)
|
📖 [Recover](https://docs.gofiber.io/api/middleware/recover)
|
||||||
|
42
.github/README_fa.md
vendored
42
.github/README_fa.md
vendored
@ -159,6 +159,7 @@ go get -u github.com/gofiber/fiber/v2
|
|||||||
- برنامه نویسی سمت سرور [سریع](https://dev.to/koddr/welcome-to-fiber-an-express-js-styled-fastest-web-framework-written-with-on-golang-497)
|
- برنامه نویسی سمت سرور [سریع](https://dev.to/koddr/welcome-to-fiber-an-express-js-styled-fastest-web-framework-written-with-on-golang-497)
|
||||||
- دارای [Template engines](https://github.com/gofiber/template) اختصاصی
|
- دارای [Template engines](https://github.com/gofiber/template) اختصاصی
|
||||||
- [پشتیبانی از وب سوکت](https://github.com/gofiber/websocket)
|
- [پشتیبانی از وب سوکت](https://github.com/gofiber/websocket)
|
||||||
|
- [Server-Sent events](https://github.com/gofiber/recipes/tree/master/sse)
|
||||||
- قابلیت [Rate Limiter](https://docs.gofiber.io/api/middleware/limiter)
|
- قابلیت [Rate Limiter](https://docs.gofiber.io/api/middleware/limiter)
|
||||||
- ترجمه در [15 زبان](https://docs.gofiber.io/)
|
- ترجمه در [15 زبان](https://docs.gofiber.io/)
|
||||||
- و امکانات بیشتر, [دیدن در داکیومنت](https://docs.gofiber.io/)
|
- و امکانات بیشتر, [دیدن در داکیومنت](https://docs.gofiber.io/)
|
||||||
@ -594,6 +595,47 @@ func main() {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Server-Sent Events
|
||||||
|
|
||||||
|
📖 [More Info](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events)
|
||||||
|
|
||||||
|
```go
|
||||||
|
import (
|
||||||
|
"github.com/gofiber/fiber/v2"
|
||||||
|
"github.com/valyala/fasthttp"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
app := fiber.New()
|
||||||
|
|
||||||
|
app.Get("/sse", func(c *fiber.Ctx) error {
|
||||||
|
c.Set("Content-Type", "text/event-stream")
|
||||||
|
c.Set("Cache-Control", "no-cache")
|
||||||
|
c.Set("Connection", "keep-alive")
|
||||||
|
c.Set("Transfer-Encoding", "chunked")
|
||||||
|
|
||||||
|
c.Context().SetBodyStreamWriter(fasthttp.StreamWriter(func(w *bufio.Writer) {
|
||||||
|
fmt.Println("WRITER")
|
||||||
|
var i int
|
||||||
|
|
||||||
|
for {
|
||||||
|
i++
|
||||||
|
msg := fmt.Sprintf("%d - the time is %v", i, time.Now())
|
||||||
|
fmt.Fprintf(w, "data: Message: %s\n\n", msg)
|
||||||
|
fmt.Println(msg)
|
||||||
|
|
||||||
|
w.Flush()
|
||||||
|
time.Sleep(5 * time.Second)
|
||||||
|
}
|
||||||
|
}))
|
||||||
|
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
|
||||||
|
log.Fatal(app.Listen(":3000"))
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
### Recover middleware
|
### Recover middleware
|
||||||
|
42
.github/README_fr.md
vendored
42
.github/README_fr.md
vendored
@ -130,6 +130,7 @@ go get -u github.com/gofiber/fiber/v2
|
|||||||
- Programmation côté serveur [rapide](https://dev.to/koddr/welcome-to-fiber-an-express-js-styled-fastest-web-framework-written-with-on-golang-497)
|
- Programmation côté serveur [rapide](https://dev.to/koddr/welcome-to-fiber-an-express-js-styled-fastest-web-framework-written-with-on-golang-497)
|
||||||
- [Template engines](https://github.com/gofiber/template)
|
- [Template engines](https://github.com/gofiber/template)
|
||||||
- [WebSocket support](https://github.com/gofiber/websocket)
|
- [WebSocket support](https://github.com/gofiber/websocket)
|
||||||
|
- [Server-Sent events](https://github.com/gofiber/recipes/tree/master/sse)
|
||||||
- [Rate Limiter](https://docs.gofiber.io/api/middleware/limiter)
|
- [Rate Limiter](https://docs.gofiber.io/api/middleware/limiter)
|
||||||
- Available in [15 languages](https://docs.gofiber.io/)
|
- Available in [15 languages](https://docs.gofiber.io/)
|
||||||
- Et plus encore, [explorez Fiber](https://docs.gofiber.io/)
|
- Et plus encore, [explorez Fiber](https://docs.gofiber.io/)
|
||||||
@ -494,6 +495,47 @@ func main() {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Server-Sent Events
|
||||||
|
|
||||||
|
📖 [More Info](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events)
|
||||||
|
|
||||||
|
```go
|
||||||
|
import (
|
||||||
|
"github.com/gofiber/fiber/v2"
|
||||||
|
"github.com/valyala/fasthttp"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
app := fiber.New()
|
||||||
|
|
||||||
|
app.Get("/sse", func(c *fiber.Ctx) error {
|
||||||
|
c.Set("Content-Type", "text/event-stream")
|
||||||
|
c.Set("Cache-Control", "no-cache")
|
||||||
|
c.Set("Connection", "keep-alive")
|
||||||
|
c.Set("Transfer-Encoding", "chunked")
|
||||||
|
|
||||||
|
c.Context().SetBodyStreamWriter(fasthttp.StreamWriter(func(w *bufio.Writer) {
|
||||||
|
fmt.Println("WRITER")
|
||||||
|
var i int
|
||||||
|
|
||||||
|
for {
|
||||||
|
i++
|
||||||
|
msg := fmt.Sprintf("%d - the time is %v", i, time.Now())
|
||||||
|
fmt.Fprintf(w, "data: Message: %s\n\n", msg)
|
||||||
|
fmt.Println(msg)
|
||||||
|
|
||||||
|
w.Flush()
|
||||||
|
time.Sleep(5 * time.Second)
|
||||||
|
}
|
||||||
|
}))
|
||||||
|
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
|
||||||
|
log.Fatal(app.Listen(":3000"))
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
### Recover middleware
|
### Recover middleware
|
||||||
|
|
||||||
📖 [Recover](https://docs.gofiber.io/api/middleware/recover)
|
📖 [Recover](https://docs.gofiber.io/api/middleware/recover)
|
||||||
|
46
.github/README_he.md
vendored
46
.github/README_he.md
vendored
@ -153,6 +153,7 @@ go get -u github.com/gofiber/fiber/v2
|
|||||||
- תכנות [מהיר](https://dev.to/koddr/welcome-to-fiber-an-express-js-styled-fastest-web-framework-written-with-on-golang-497) של צד שרת
|
- תכנות [מהיר](https://dev.to/koddr/welcome-to-fiber-an-express-js-styled-fastest-web-framework-written-with-on-golang-497) של צד שרת
|
||||||
- [מנועי תבניות](https://docs.gofiber.io/middleware#template)
|
- [מנועי תבניות](https://docs.gofiber.io/middleware#template)
|
||||||
- [תמיכה ב-WebSocket](https://github.com/gofiber/websocket)
|
- [תמיכה ב-WebSocket](https://github.com/gofiber/websocket)
|
||||||
|
- [Server-Sent events](https://github.com/gofiber/recipes/tree/master/sse)
|
||||||
- [הגבלת קצבים ובקשות](https://docs.gofiber.io/api/middleware/limiter)
|
- [הגבלת קצבים ובקשות](https://docs.gofiber.io/api/middleware/limiter)
|
||||||
- Available in [12 languages](https://docs.gofiber.io/)
|
- Available in [12 languages](https://docs.gofiber.io/)
|
||||||
- והרבה יותר, [חקור את Fiber](https://docs.gofiber.io/)
|
- והרבה יותר, [חקור את Fiber](https://docs.gofiber.io/)
|
||||||
@ -592,6 +593,51 @@ func main() {
|
|||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
### Server-Sent Events
|
||||||
|
|
||||||
|
📖 [More Info](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events)
|
||||||
|
|
||||||
|
<div dir="ltr">
|
||||||
|
|
||||||
|
```go
|
||||||
|
import (
|
||||||
|
"github.com/gofiber/fiber/v2"
|
||||||
|
"github.com/valyala/fasthttp"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
app := fiber.New()
|
||||||
|
|
||||||
|
app.Get("/sse", func(c *fiber.Ctx) error {
|
||||||
|
c.Set("Content-Type", "text/event-stream")
|
||||||
|
c.Set("Cache-Control", "no-cache")
|
||||||
|
c.Set("Connection", "keep-alive")
|
||||||
|
c.Set("Transfer-Encoding", "chunked")
|
||||||
|
|
||||||
|
c.Context().SetBodyStreamWriter(fasthttp.StreamWriter(func(w *bufio.Writer) {
|
||||||
|
fmt.Println("WRITER")
|
||||||
|
var i int
|
||||||
|
|
||||||
|
for {
|
||||||
|
i++
|
||||||
|
msg := fmt.Sprintf("%d - the time is %v", i, time.Now())
|
||||||
|
fmt.Fprintf(w, "data: Message: %s\n\n", msg)
|
||||||
|
fmt.Println(msg)
|
||||||
|
|
||||||
|
w.Flush()
|
||||||
|
time.Sleep(5 * time.Second)
|
||||||
|
}
|
||||||
|
}))
|
||||||
|
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
|
||||||
|
log.Fatal(app.Listen(":3000"))
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
### Middleware של התאוששות
|
### Middleware של התאוששות
|
||||||
|
|
||||||
📖 [התאוששות](https://docs.gofiber.io/api/middleware/recover)
|
📖 [התאוששות](https://docs.gofiber.io/api/middleware/recover)
|
||||||
|
42
.github/README_id.md
vendored
42
.github/README_id.md
vendored
@ -130,6 +130,7 @@ go get -u github.com/gofiber/fiber/v2
|
|||||||
- Kembangkan aplikasi dengan [Cepat](https://dev.to/koddr/welcome-to-fiber-an-express-js-styled-fastest-web-framework-written-with-on-golang-497)
|
- Kembangkan aplikasi dengan [Cepat](https://dev.to/koddr/welcome-to-fiber-an-express-js-styled-fastest-web-framework-written-with-on-golang-497)
|
||||||
- [Template engines](https://github.com/gofiber/template)
|
- [Template engines](https://github.com/gofiber/template)
|
||||||
- [Mendukung WebSocket](https://github.com/gofiber/websocket)
|
- [Mendukung WebSocket](https://github.com/gofiber/websocket)
|
||||||
|
- [Server-Sent events](https://github.com/gofiber/recipes/tree/master/sse)
|
||||||
- [Rate Limiter](https://docs.gofiber.io/api/middleware/limiter)
|
- [Rate Limiter](https://docs.gofiber.io/api/middleware/limiter)
|
||||||
- Tersedia dalam [15 bahasa](https://docs.gofiber.io/)
|
- Tersedia dalam [15 bahasa](https://docs.gofiber.io/)
|
||||||
- Dan masih banyak lagi, [kunjungi Fiber](https://docs.gofiber.io/)
|
- Dan masih banyak lagi, [kunjungi Fiber](https://docs.gofiber.io/)
|
||||||
@ -495,6 +496,47 @@ func main() {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Server-Sent Events
|
||||||
|
|
||||||
|
📖 [More Info](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events)
|
||||||
|
|
||||||
|
```go
|
||||||
|
import (
|
||||||
|
"github.com/gofiber/fiber/v2"
|
||||||
|
"github.com/valyala/fasthttp"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
app := fiber.New()
|
||||||
|
|
||||||
|
app.Get("/sse", func(c *fiber.Ctx) error {
|
||||||
|
c.Set("Content-Type", "text/event-stream")
|
||||||
|
c.Set("Cache-Control", "no-cache")
|
||||||
|
c.Set("Connection", "keep-alive")
|
||||||
|
c.Set("Transfer-Encoding", "chunked")
|
||||||
|
|
||||||
|
c.Context().SetBodyStreamWriter(fasthttp.StreamWriter(func(w *bufio.Writer) {
|
||||||
|
fmt.Println("WRITER")
|
||||||
|
var i int
|
||||||
|
|
||||||
|
for {
|
||||||
|
i++
|
||||||
|
msg := fmt.Sprintf("%d - the time is %v", i, time.Now())
|
||||||
|
fmt.Fprintf(w, "data: Message: %s\n\n", msg)
|
||||||
|
fmt.Println(msg)
|
||||||
|
|
||||||
|
w.Flush()
|
||||||
|
time.Sleep(5 * time.Second)
|
||||||
|
}
|
||||||
|
}))
|
||||||
|
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
|
||||||
|
log.Fatal(app.Listen(":3000"))
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
### Recover middleware
|
### Recover middleware
|
||||||
|
|
||||||
📖 [Recover](https://docs.gofiber.io/api/middleware/recover)
|
📖 [Recover](https://docs.gofiber.io/api/middleware/recover)
|
||||||
|
42
.github/README_it.md
vendored
42
.github/README_it.md
vendored
@ -130,6 +130,7 @@ go get -u github.com/gofiber/fiber/v2
|
|||||||
- Programmazione server-side [veloce](https://dev.to/koddr/welcome-to-fiber-an-express-js-styled-fastest-web-framework-written-with-on-golang-497)
|
- Programmazione server-side [veloce](https://dev.to/koddr/welcome-to-fiber-an-express-js-styled-fastest-web-framework-written-with-on-golang-497)
|
||||||
- [Template engine](https://github.com/gofiber/template)
|
- [Template engine](https://github.com/gofiber/template)
|
||||||
- [Supporto WebSocket](https://github.com/gofiber/websocket)
|
- [Supporto WebSocket](https://github.com/gofiber/websocket)
|
||||||
|
- [Server-Sent events](https://github.com/gofiber/recipes/tree/master/sse)
|
||||||
- [Rate Limiter](https://docs.gofiber.io/api/middleware/limiter)
|
- [Rate Limiter](https://docs.gofiber.io/api/middleware/limiter)
|
||||||
- Disponible in [15 lingue](https://docs.gofiber.io/)
|
- Disponible in [15 lingue](https://docs.gofiber.io/)
|
||||||
- E molto altro ancora, [esplora Fiber](https://docs.gofiber.io/)
|
- E molto altro ancora, [esplora Fiber](https://docs.gofiber.io/)
|
||||||
@ -493,6 +494,47 @@ func main() {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Server-Sent Events
|
||||||
|
|
||||||
|
📖 [More Info](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events)
|
||||||
|
|
||||||
|
```go
|
||||||
|
import (
|
||||||
|
"github.com/gofiber/fiber/v2"
|
||||||
|
"github.com/valyala/fasthttp"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
app := fiber.New()
|
||||||
|
|
||||||
|
app.Get("/sse", func(c *fiber.Ctx) error {
|
||||||
|
c.Set("Content-Type", "text/event-stream")
|
||||||
|
c.Set("Cache-Control", "no-cache")
|
||||||
|
c.Set("Connection", "keep-alive")
|
||||||
|
c.Set("Transfer-Encoding", "chunked")
|
||||||
|
|
||||||
|
c.Context().SetBodyStreamWriter(fasthttp.StreamWriter(func(w *bufio.Writer) {
|
||||||
|
fmt.Println("WRITER")
|
||||||
|
var i int
|
||||||
|
|
||||||
|
for {
|
||||||
|
i++
|
||||||
|
msg := fmt.Sprintf("%d - the time is %v", i, time.Now())
|
||||||
|
fmt.Fprintf(w, "data: Message: %s\n\n", msg)
|
||||||
|
fmt.Println(msg)
|
||||||
|
|
||||||
|
w.Flush()
|
||||||
|
time.Sleep(5 * time.Second)
|
||||||
|
}
|
||||||
|
}))
|
||||||
|
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
|
||||||
|
log.Fatal(app.Listen(":3000"))
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
### Recover middleware
|
### Recover middleware
|
||||||
|
|
||||||
📖 [Recover](https://docs.gofiber.io/api/middleware/recover)
|
📖 [Recover](https://docs.gofiber.io/api/middleware/recover)
|
||||||
|
42
.github/README_ja.md
vendored
42
.github/README_ja.md
vendored
@ -132,6 +132,7 @@ go get -u github.com/gofiber/fiber/v2
|
|||||||
- [迅速](https://dev.to/koddr/welcome-to-fiber-an-express-js-styled-fastest-web-framework-written-with-on-golang-497)なサーバーサイドプログラミング
|
- [迅速](https://dev.to/koddr/welcome-to-fiber-an-express-js-styled-fastest-web-framework-written-with-on-golang-497)なサーバーサイドプログラミング
|
||||||
- [Template engines](https://github.com/gofiber/template)
|
- [Template engines](https://github.com/gofiber/template)
|
||||||
- [WebSocket support](https://github.com/gofiber/websocket)
|
- [WebSocket support](https://github.com/gofiber/websocket)
|
||||||
|
- [Server-Sent events](https://github.com/gofiber/recipes/tree/master/sse)
|
||||||
- [Rate Limiter](https://docs.gofiber.io/api/middleware/limiter)
|
- [Rate Limiter](https://docs.gofiber.io/api/middleware/limiter)
|
||||||
- [15 ヶ国語](https://docs.gofiber.io/)で利用可能
|
- [15 ヶ国語](https://docs.gofiber.io/)で利用可能
|
||||||
- [Fiber](https://docs.gofiber.io/)をもっと知る
|
- [Fiber](https://docs.gofiber.io/)をもっと知る
|
||||||
@ -497,6 +498,47 @@ func main() {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Server-Sent Events
|
||||||
|
|
||||||
|
📖 [More Info](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events)
|
||||||
|
|
||||||
|
```go
|
||||||
|
import (
|
||||||
|
"github.com/gofiber/fiber/v2"
|
||||||
|
"github.com/valyala/fasthttp"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
app := fiber.New()
|
||||||
|
|
||||||
|
app.Get("/sse", func(c *fiber.Ctx) error {
|
||||||
|
c.Set("Content-Type", "text/event-stream")
|
||||||
|
c.Set("Cache-Control", "no-cache")
|
||||||
|
c.Set("Connection", "keep-alive")
|
||||||
|
c.Set("Transfer-Encoding", "chunked")
|
||||||
|
|
||||||
|
c.Context().SetBodyStreamWriter(fasthttp.StreamWriter(func(w *bufio.Writer) {
|
||||||
|
fmt.Println("WRITER")
|
||||||
|
var i int
|
||||||
|
|
||||||
|
for {
|
||||||
|
i++
|
||||||
|
msg := fmt.Sprintf("%d - the time is %v", i, time.Now())
|
||||||
|
fmt.Fprintf(w, "data: Message: %s\n\n", msg)
|
||||||
|
fmt.Println(msg)
|
||||||
|
|
||||||
|
w.Flush()
|
||||||
|
time.Sleep(5 * time.Second)
|
||||||
|
}
|
||||||
|
}))
|
||||||
|
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
|
||||||
|
log.Fatal(app.Listen(":3000"))
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
### Recover middleware
|
### Recover middleware
|
||||||
|
|
||||||
📖 [Recover](https://docs.gofiber.io/api/middleware/recover)
|
📖 [Recover](https://docs.gofiber.io/api/middleware/recover)
|
||||||
|
42
.github/README_ko.md
vendored
42
.github/README_ko.md
vendored
@ -130,6 +130,7 @@ go get -u github.com/gofiber/fiber/v2
|
|||||||
- [빠른](https://dev.to/koddr/welcome-to-fiber-an-express-js-styled-fastest-web-framework-written-with-on-golang-497) 서버 사이드 프로그래밍
|
- [빠른](https://dev.to/koddr/welcome-to-fiber-an-express-js-styled-fastest-web-framework-written-with-on-golang-497) 서버 사이드 프로그래밍
|
||||||
- [Template engines](https://github.com/gofiber/template)
|
- [Template engines](https://github.com/gofiber/template)
|
||||||
- [WebSocket support](https://github.com/gofiber/websocket)
|
- [WebSocket support](https://github.com/gofiber/websocket)
|
||||||
|
- [Server-Sent events](https://github.com/gofiber/recipes/tree/master/sse)
|
||||||
- [Rate Limiter](https://docs.gofiber.io/api/middleware/limiter)
|
- [Rate Limiter](https://docs.gofiber.io/api/middleware/limiter)
|
||||||
- Available in [15 languages](https://docs.gofiber.io/)
|
- Available in [15 languages](https://docs.gofiber.io/)
|
||||||
- 더 알고 싶다면, [Fiber 둘러보기](https://docs.gofiber.io/)
|
- 더 알고 싶다면, [Fiber 둘러보기](https://docs.gofiber.io/)
|
||||||
@ -498,6 +499,47 @@ func main() {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Server-Sent Events
|
||||||
|
|
||||||
|
📖 [More Info](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events)
|
||||||
|
|
||||||
|
```go
|
||||||
|
import (
|
||||||
|
"github.com/gofiber/fiber/v2"
|
||||||
|
"github.com/valyala/fasthttp"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
app := fiber.New()
|
||||||
|
|
||||||
|
app.Get("/sse", func(c *fiber.Ctx) error {
|
||||||
|
c.Set("Content-Type", "text/event-stream")
|
||||||
|
c.Set("Cache-Control", "no-cache")
|
||||||
|
c.Set("Connection", "keep-alive")
|
||||||
|
c.Set("Transfer-Encoding", "chunked")
|
||||||
|
|
||||||
|
c.Context().SetBodyStreamWriter(fasthttp.StreamWriter(func(w *bufio.Writer) {
|
||||||
|
fmt.Println("WRITER")
|
||||||
|
var i int
|
||||||
|
|
||||||
|
for {
|
||||||
|
i++
|
||||||
|
msg := fmt.Sprintf("%d - the time is %v", i, time.Now())
|
||||||
|
fmt.Fprintf(w, "data: Message: %s\n\n", msg)
|
||||||
|
fmt.Println(msg)
|
||||||
|
|
||||||
|
w.Flush()
|
||||||
|
time.Sleep(5 * time.Second)
|
||||||
|
}
|
||||||
|
}))
|
||||||
|
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
|
||||||
|
log.Fatal(app.Listen(":3000"))
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
### Recover middleware
|
### Recover middleware
|
||||||
|
|
||||||
📖 [Recover](https://docs.gofiber.io/api/middleware/recover)
|
📖 [Recover](https://docs.gofiber.io/api/middleware/recover)
|
||||||
|
42
.github/README_nl.md
vendored
42
.github/README_nl.md
vendored
@ -130,6 +130,7 @@ go get -u github.com/gofiber/fiber/v2
|
|||||||
- [Snelle](https://dev.to/koddr/welcome-to-fiber-an-express-js-styled-fastest-web-framework-written-with-on-golang-497) server-side programmering
|
- [Snelle](https://dev.to/koddr/welcome-to-fiber-an-express-js-styled-fastest-web-framework-written-with-on-golang-497) server-side programmering
|
||||||
- [Template engines](https://github.com/gofiber/template)
|
- [Template engines](https://github.com/gofiber/template)
|
||||||
- [WebSocket ondersteuning](https://github.com/gofiber/websocket)
|
- [WebSocket ondersteuning](https://github.com/gofiber/websocket)
|
||||||
|
- [Server-Sent events](https://github.com/gofiber/recipes/tree/master/sse)
|
||||||
- [Rate Limiter](https://docs.gofiber.io/middleware/limiter)
|
- [Rate Limiter](https://docs.gofiber.io/middleware/limiter)
|
||||||
- Vertaald in [15 talen](https://docs.gofiber.io/)
|
- Vertaald in [15 talen](https://docs.gofiber.io/)
|
||||||
- En nog veel meer, [ontdek Fiber](https://docs.gofiber.io/)
|
- En nog veel meer, [ontdek Fiber](https://docs.gofiber.io/)
|
||||||
@ -498,6 +499,47 @@ func main() {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Server-Sent Events
|
||||||
|
|
||||||
|
📖 [More Info](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events)
|
||||||
|
|
||||||
|
```go
|
||||||
|
import (
|
||||||
|
"github.com/gofiber/fiber/v2"
|
||||||
|
"github.com/valyala/fasthttp"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
app := fiber.New()
|
||||||
|
|
||||||
|
app.Get("/sse", func(c *fiber.Ctx) error {
|
||||||
|
c.Set("Content-Type", "text/event-stream")
|
||||||
|
c.Set("Cache-Control", "no-cache")
|
||||||
|
c.Set("Connection", "keep-alive")
|
||||||
|
c.Set("Transfer-Encoding", "chunked")
|
||||||
|
|
||||||
|
c.Context().SetBodyStreamWriter(fasthttp.StreamWriter(func(w *bufio.Writer) {
|
||||||
|
fmt.Println("WRITER")
|
||||||
|
var i int
|
||||||
|
|
||||||
|
for {
|
||||||
|
i++
|
||||||
|
msg := fmt.Sprintf("%d - the time is %v", i, time.Now())
|
||||||
|
fmt.Fprintf(w, "data: Message: %s\n\n", msg)
|
||||||
|
fmt.Println(msg)
|
||||||
|
|
||||||
|
w.Flush()
|
||||||
|
time.Sleep(5 * time.Second)
|
||||||
|
}
|
||||||
|
}))
|
||||||
|
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
|
||||||
|
log.Fatal(app.Listen(":3000"))
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
### Recover middleware
|
### Recover middleware
|
||||||
|
|
||||||
📖 [Recover](https://docs.gofiber.io/api/middleware/recover)
|
📖 [Recover](https://docs.gofiber.io/api/middleware/recover)
|
||||||
|
42
.github/README_pt.md
vendored
42
.github/README_pt.md
vendored
@ -130,6 +130,7 @@ go get -u github.com/gofiber/fiber/v2
|
|||||||
- Programação [rápida](https://dev.to/koddr/welcome-to-fiber-an-express-js-styled-fastest-web-framework-written-with-on-golang-497) de aplicações de servidor
|
- Programação [rápida](https://dev.to/koddr/welcome-to-fiber-an-express-js-styled-fastest-web-framework-written-with-on-golang-497) de aplicações de servidor
|
||||||
- [Templates](https://github.com/gofiber/template)
|
- [Templates](https://github.com/gofiber/template)
|
||||||
- [Suporte à WebSockets](https://github.com/gofiber/websocket)
|
- [Suporte à WebSockets](https://github.com/gofiber/websocket)
|
||||||
|
- [Server-Sent events](https://github.com/gofiber/recipes/tree/master/sse)
|
||||||
- [Limitador de requisições](https://docs.gofiber.io/api/middleware/limiter)
|
- [Limitador de requisições](https://docs.gofiber.io/api/middleware/limiter)
|
||||||
- Disponível em [15 línguas](https://docs.gofiber.io/)
|
- Disponível em [15 línguas](https://docs.gofiber.io/)
|
||||||
- E muito mais, [explore o Fiber](https://docs.gofiber.io/)
|
- E muito mais, [explore o Fiber](https://docs.gofiber.io/)
|
||||||
@ -492,6 +493,47 @@ func main() {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Server-Sent Events
|
||||||
|
|
||||||
|
📖 [More Info](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events)
|
||||||
|
|
||||||
|
```go
|
||||||
|
import (
|
||||||
|
"github.com/gofiber/fiber/v2"
|
||||||
|
"github.com/valyala/fasthttp"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
app := fiber.New()
|
||||||
|
|
||||||
|
app.Get("/sse", func(c *fiber.Ctx) error {
|
||||||
|
c.Set("Content-Type", "text/event-stream")
|
||||||
|
c.Set("Cache-Control", "no-cache")
|
||||||
|
c.Set("Connection", "keep-alive")
|
||||||
|
c.Set("Transfer-Encoding", "chunked")
|
||||||
|
|
||||||
|
c.Context().SetBodyStreamWriter(fasthttp.StreamWriter(func(w *bufio.Writer) {
|
||||||
|
fmt.Println("WRITER")
|
||||||
|
var i int
|
||||||
|
|
||||||
|
for {
|
||||||
|
i++
|
||||||
|
msg := fmt.Sprintf("%d - the time is %v", i, time.Now())
|
||||||
|
fmt.Fprintf(w, "data: Message: %s\n\n", msg)
|
||||||
|
fmt.Println(msg)
|
||||||
|
|
||||||
|
w.Flush()
|
||||||
|
time.Sleep(5 * time.Second)
|
||||||
|
}
|
||||||
|
}))
|
||||||
|
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
|
||||||
|
log.Fatal(app.Listen(":3000"))
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
### Middleware Recover
|
### Middleware Recover
|
||||||
|
|
||||||
📖 [Recover](https://docs.gofiber.io/api/middleware/recover)
|
📖 [Recover](https://docs.gofiber.io/api/middleware/recover)
|
||||||
|
42
.github/README_ru.md
vendored
42
.github/README_ru.md
vendored
@ -130,6 +130,7 @@ go get -u github.com/gofiber/fiber/v2
|
|||||||
- [Быстрое](https://dev.to/koddr/welcome-to-fiber-an-express-js-styled-fastest-web-framework-written-with-on-golang-497) программирование на стороне сервера
|
- [Быстрое](https://dev.to/koddr/welcome-to-fiber-an-express-js-styled-fastest-web-framework-written-with-on-golang-497) программирование на стороне сервера
|
||||||
- [Template engines](https://github.com/gofiber/template)
|
- [Template engines](https://github.com/gofiber/template)
|
||||||
- [Поддержка WebSocket](https://github.com/gofiber/websocket)
|
- [Поддержка WebSocket](https://github.com/gofiber/websocket)
|
||||||
|
- [Server-Sent events](https://github.com/gofiber/recipes/tree/master/sse)
|
||||||
- [Rate Limiter](https://docs.gofiber.io/api/middleware/limiter)
|
- [Rate Limiter](https://docs.gofiber.io/api/middleware/limiter)
|
||||||
- Документация доступна на [15 языках](https://docs.gofiber.io/)
|
- Документация доступна на [15 языках](https://docs.gofiber.io/)
|
||||||
- И многое другое, [посетите наш Wiki](https://docs.gofiber.io/)
|
- И многое другое, [посетите наш Wiki](https://docs.gofiber.io/)
|
||||||
@ -498,6 +499,47 @@ func main() {
|
|||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Server-Sent Events
|
||||||
|
|
||||||
|
📖 [More Info](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events)
|
||||||
|
|
||||||
|
```go
|
||||||
|
import (
|
||||||
|
"github.com/gofiber/fiber/v2"
|
||||||
|
"github.com/valyala/fasthttp"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
app := fiber.New()
|
||||||
|
|
||||||
|
app.Get("/sse", func(c *fiber.Ctx) error {
|
||||||
|
c.Set("Content-Type", "text/event-stream")
|
||||||
|
c.Set("Cache-Control", "no-cache")
|
||||||
|
c.Set("Connection", "keep-alive")
|
||||||
|
c.Set("Transfer-Encoding", "chunked")
|
||||||
|
|
||||||
|
c.Context().SetBodyStreamWriter(fasthttp.StreamWriter(func(w *bufio.Writer) {
|
||||||
|
fmt.Println("WRITER")
|
||||||
|
var i int
|
||||||
|
|
||||||
|
for {
|
||||||
|
i++
|
||||||
|
msg := fmt.Sprintf("%d - the time is %v", i, time.Now())
|
||||||
|
fmt.Fprintf(w, "data: Message: %s\n\n", msg)
|
||||||
|
fmt.Println(msg)
|
||||||
|
|
||||||
|
w.Flush()
|
||||||
|
time.Sleep(5 * time.Second)
|
||||||
|
}
|
||||||
|
}))
|
||||||
|
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
|
||||||
|
log.Fatal(app.Listen(":3000"))
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
### Recover middleware
|
### Recover middleware
|
||||||
|
|
||||||
📖 [Recover](https://docs.gofiber.io/api/middleware/recover)
|
📖 [Recover](https://docs.gofiber.io/api/middleware/recover)
|
||||||
|
46
.github/README_sa.md
vendored
46
.github/README_sa.md
vendored
@ -143,6 +143,7 @@ go get -u github.com/gofiber/fiber/v2
|
|||||||
- [سريع](https://dev.to/koddr/welcome-to-fiber-an-express-js-styled-fastest-web-framework-written-with-on-golang-497) server-side programming
|
- [سريع](https://dev.to/koddr/welcome-to-fiber-an-express-js-styled-fastest-web-framework-written-with-on-golang-497) server-side programming
|
||||||
- [Template engines](https://github.com/gofiber/template)
|
- [Template engines](https://github.com/gofiber/template)
|
||||||
- [WebSocket دعم](https://github.com/gofiber/websocket)
|
- [WebSocket دعم](https://github.com/gofiber/websocket)
|
||||||
|
- [Server-Sent events](https://github.com/gofiber/recipes/tree/master/sse)
|
||||||
- [Rate Limiter](https://docs.gofiber.io/api/middleware/limiter)
|
- [Rate Limiter](https://docs.gofiber.io/api/middleware/limiter)
|
||||||
- ترجم الى [15 لغة أخرى](https://docs.gofiber.io/)
|
- ترجم الى [15 لغة أخرى](https://docs.gofiber.io/)
|
||||||
- وأكثر بكثير, [استكشف Fiber](https://docs.gofiber.io/)
|
- وأكثر بكثير, [استكشف Fiber](https://docs.gofiber.io/)
|
||||||
@ -556,6 +557,51 @@ func main() {
|
|||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
### Server-Sent Events
|
||||||
|
|
||||||
|
📖 [More Info](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events)
|
||||||
|
|
||||||
|
<div dir="ltr">
|
||||||
|
|
||||||
|
```go
|
||||||
|
import (
|
||||||
|
"github.com/gofiber/fiber/v2"
|
||||||
|
"github.com/valyala/fasthttp"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
app := fiber.New()
|
||||||
|
|
||||||
|
app.Get("/sse", func(c *fiber.Ctx) error {
|
||||||
|
c.Set("Content-Type", "text/event-stream")
|
||||||
|
c.Set("Cache-Control", "no-cache")
|
||||||
|
c.Set("Connection", "keep-alive")
|
||||||
|
c.Set("Transfer-Encoding", "chunked")
|
||||||
|
|
||||||
|
c.Context().SetBodyStreamWriter(fasthttp.StreamWriter(func(w *bufio.Writer) {
|
||||||
|
fmt.Println("WRITER")
|
||||||
|
var i int
|
||||||
|
|
||||||
|
for {
|
||||||
|
i++
|
||||||
|
msg := fmt.Sprintf("%d - the time is %v", i, time.Now())
|
||||||
|
fmt.Fprintf(w, "data: Message: %s\n\n", msg)
|
||||||
|
fmt.Println(msg)
|
||||||
|
|
||||||
|
w.Flush()
|
||||||
|
time.Sleep(5 * time.Second)
|
||||||
|
}
|
||||||
|
}))
|
||||||
|
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
|
||||||
|
log.Fatal(app.Listen(":3000"))
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
### Recover middleware
|
### Recover middleware
|
||||||
|
|
||||||
📖 [Recover](https://docs.gofiber.io/api/middleware/recover)
|
📖 [Recover](https://docs.gofiber.io/api/middleware/recover)
|
||||||
|
42
.github/README_tr.md
vendored
42
.github/README_tr.md
vendored
@ -130,6 +130,7 @@ go get -u github.com/gofiber/fiber/v2
|
|||||||
- [Hızlı](https://dev.to/koddr/welcome-to-fiber-an-express-js-styled-fastest-web-framework-written-with-on-golang-497) sunucu taraflı programlama
|
- [Hızlı](https://dev.to/koddr/welcome-to-fiber-an-express-js-styled-fastest-web-framework-written-with-on-golang-497) sunucu taraflı programlama
|
||||||
- [Template engines](https://github.com/gofiber/template)
|
- [Template engines](https://github.com/gofiber/template)
|
||||||
- [WebSocket support](https://github.com/gofiber/websocket)
|
- [WebSocket support](https://github.com/gofiber/websocket)
|
||||||
|
- [Server-Sent events](https://github.com/gofiber/recipes/tree/master/sse)
|
||||||
- [Rate Limiter](https://docs.gofiber.io/api/middleware/limiter)
|
- [Rate Limiter](https://docs.gofiber.io/api/middleware/limiter)
|
||||||
- [15 dilde](https://docs.gofiber.io/) mevcut
|
- [15 dilde](https://docs.gofiber.io/) mevcut
|
||||||
- Ve daha fazlası, [Fiber'ı keşfet](https://docs.gofiber.io/)
|
- Ve daha fazlası, [Fiber'ı keşfet](https://docs.gofiber.io/)
|
||||||
@ -492,6 +493,47 @@ func main() {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Server-Sent Events
|
||||||
|
|
||||||
|
📖 [More Info](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events)
|
||||||
|
|
||||||
|
```go
|
||||||
|
import (
|
||||||
|
"github.com/gofiber/fiber/v2"
|
||||||
|
"github.com/valyala/fasthttp"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
app := fiber.New()
|
||||||
|
|
||||||
|
app.Get("/sse", func(c *fiber.Ctx) error {
|
||||||
|
c.Set("Content-Type", "text/event-stream")
|
||||||
|
c.Set("Cache-Control", "no-cache")
|
||||||
|
c.Set("Connection", "keep-alive")
|
||||||
|
c.Set("Transfer-Encoding", "chunked")
|
||||||
|
|
||||||
|
c.Context().SetBodyStreamWriter(fasthttp.StreamWriter(func(w *bufio.Writer) {
|
||||||
|
fmt.Println("WRITER")
|
||||||
|
var i int
|
||||||
|
|
||||||
|
for {
|
||||||
|
i++
|
||||||
|
msg := fmt.Sprintf("%d - the time is %v", i, time.Now())
|
||||||
|
fmt.Fprintf(w, "data: Message: %s\n\n", msg)
|
||||||
|
fmt.Println(msg)
|
||||||
|
|
||||||
|
w.Flush()
|
||||||
|
time.Sleep(5 * time.Second)
|
||||||
|
}
|
||||||
|
}))
|
||||||
|
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
|
||||||
|
log.Fatal(app.Listen(":3000"))
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
### Middleware Kurtarıcısı
|
### Middleware Kurtarıcısı
|
||||||
|
|
||||||
📖 [Recover](https://docs.gofiber.io/api/middleware/recover)
|
📖 [Recover](https://docs.gofiber.io/api/middleware/recover)
|
||||||
|
42
.github/README_zh-CN.md
vendored
42
.github/README_zh-CN.md
vendored
@ -130,6 +130,7 @@ go get -u github.com/gofiber/fiber/v2
|
|||||||
- [快速](https://dev.to/koddr/welcome-to-fiber-an-express-js-styled-fastest-web-framework-written-with-on-golang-497)服务器端编程
|
- [快速](https://dev.to/koddr/welcome-to-fiber-an-express-js-styled-fastest-web-framework-written-with-on-golang-497)服务器端编程
|
||||||
- [模版引擎](https://github.com/gofiber/template)
|
- [模版引擎](https://github.com/gofiber/template)
|
||||||
- [WebSocket 支持](https://github.com/gofiber/websocket)
|
- [WebSocket 支持](https://github.com/gofiber/websocket)
|
||||||
|
- [Server-Sent events](https://github.com/gofiber/recipes/tree/master/sse)
|
||||||
- [频率限制](https://docs.gofiber.io/api/middleware/limiter)
|
- [频率限制](https://docs.gofiber.io/api/middleware/limiter)
|
||||||
- [15 种语言](https://docs.gofiber.io/)
|
- [15 种语言](https://docs.gofiber.io/)
|
||||||
- 更多请[探索文档](https://docs.gofiber.io/)
|
- 更多请[探索文档](https://docs.gofiber.io/)
|
||||||
@ -494,6 +495,47 @@ func main() {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Server-Sent Events
|
||||||
|
|
||||||
|
📖 [More Info](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events)
|
||||||
|
|
||||||
|
```go
|
||||||
|
import (
|
||||||
|
"github.com/gofiber/fiber/v2"
|
||||||
|
"github.com/valyala/fasthttp"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
app := fiber.New()
|
||||||
|
|
||||||
|
app.Get("/sse", func(c *fiber.Ctx) error {
|
||||||
|
c.Set("Content-Type", "text/event-stream")
|
||||||
|
c.Set("Cache-Control", "no-cache")
|
||||||
|
c.Set("Connection", "keep-alive")
|
||||||
|
c.Set("Transfer-Encoding", "chunked")
|
||||||
|
|
||||||
|
c.Context().SetBodyStreamWriter(fasthttp.StreamWriter(func(w *bufio.Writer) {
|
||||||
|
fmt.Println("WRITER")
|
||||||
|
var i int
|
||||||
|
|
||||||
|
for {
|
||||||
|
i++
|
||||||
|
msg := fmt.Sprintf("%d - the time is %v", i, time.Now())
|
||||||
|
fmt.Fprintf(w, "data: Message: %s\n\n", msg)
|
||||||
|
fmt.Println(msg)
|
||||||
|
|
||||||
|
w.Flush()
|
||||||
|
time.Sleep(5 * time.Second)
|
||||||
|
}
|
||||||
|
}))
|
||||||
|
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
|
||||||
|
log.Fatal(app.Listen(":3000"))
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
### 恢复(panic)中间件
|
### 恢复(panic)中间件
|
||||||
|
|
||||||
📖 [Recover](https://docs.gofiber.io/api/middleware/recover)
|
📖 [Recover](https://docs.gofiber.io/api/middleware/recover)
|
||||||
|
42
.github/README_zh-TW.md
vendored
42
.github/README_zh-TW.md
vendored
@ -130,6 +130,7 @@ go get -u github.com/gofiber/fiber/v2
|
|||||||
- [立即上手](https://dev.to/koddr/welcome-to-fiber-an-express-js-styled-fastest-web-framework-written-with-on-golang-497)
|
- [立即上手](https://dev.to/koddr/welcome-to-fiber-an-express-js-styled-fastest-web-framework-written-with-on-golang-497)
|
||||||
- [樣板引擎](https://github.com/gofiber/template)
|
- [樣板引擎](https://github.com/gofiber/template)
|
||||||
- 支援[WebSocket](https://github.com/gofiber/websocket)
|
- 支援[WebSocket](https://github.com/gofiber/websocket)
|
||||||
|
- [Server-Sent events](https://github.com/gofiber/recipes/tree/master/sse)
|
||||||
- 支援[限速](https://docs.gofiber.io/api/middleware/limiter)
|
- 支援[限速](https://docs.gofiber.io/api/middleware/limiter)
|
||||||
- 被翻譯成[15種語言](https://docs.gofiber.io/)
|
- 被翻譯成[15種語言](https://docs.gofiber.io/)
|
||||||
- 豐富的[文件](https://docs.gofiber.io/)
|
- 豐富的[文件](https://docs.gofiber.io/)
|
||||||
@ -495,6 +496,47 @@ func main() {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Server-Sent Events
|
||||||
|
|
||||||
|
📖 [More Info](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events)
|
||||||
|
|
||||||
|
```go
|
||||||
|
import (
|
||||||
|
"github.com/gofiber/fiber/v2"
|
||||||
|
"github.com/valyala/fasthttp"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
app := fiber.New()
|
||||||
|
|
||||||
|
app.Get("/sse", func(c *fiber.Ctx) error {
|
||||||
|
c.Set("Content-Type", "text/event-stream")
|
||||||
|
c.Set("Cache-Control", "no-cache")
|
||||||
|
c.Set("Connection", "keep-alive")
|
||||||
|
c.Set("Transfer-Encoding", "chunked")
|
||||||
|
|
||||||
|
c.Context().SetBodyStreamWriter(fasthttp.StreamWriter(func(w *bufio.Writer) {
|
||||||
|
fmt.Println("WRITER")
|
||||||
|
var i int
|
||||||
|
|
||||||
|
for {
|
||||||
|
i++
|
||||||
|
msg := fmt.Sprintf("%d - the time is %v", i, time.Now())
|
||||||
|
fmt.Fprintf(w, "data: Message: %s\n\n", msg)
|
||||||
|
fmt.Println(msg)
|
||||||
|
|
||||||
|
w.Flush()
|
||||||
|
time.Sleep(5 * time.Second)
|
||||||
|
}
|
||||||
|
}))
|
||||||
|
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
|
||||||
|
log.Fatal(app.Listen(":3000"))
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
### Recover 中介器
|
### Recover 中介器
|
||||||
|
|
||||||
📖 [Recover](https://docs.gofiber.io/api/middleware/recover)
|
📖 [Recover](https://docs.gofiber.io/api/middleware/recover)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user