mirror of https://github.com/gofiber/fiber.git
docs: add SSE example (#1776)
parent
daab00c36e
commit
e1833df93c
|
@ -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
|
||||
- [Template engines](https://github.com/gofiber/template)
|
||||
- [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)
|
||||
- Translated in [15 languages](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](https://docs.gofiber.io/api/middleware/recover)
|
||||
|
|
|
@ -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://github.com/gofiber/template)
|
||||
- پشتگیریی [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)
|
||||
- وەرگێڕراوە بۆ [15 زمان](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](https://docs.gofiber.io/api/middleware/recover)
|
||||
|
|
|
@ -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
|
||||
- [Template engines](https://github.com/gofiber/template)
|
||||
- [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)
|
||||
- Verfügbar in [15 Sprachen](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](https://docs.gofiber.io/api/middleware/recover)
|
||||
|
|
|
@ -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
|
||||
- [Template engines](https://github.com/gofiber/template)
|
||||
- [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)
|
||||
- Disponible en [15 idiomas](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
|
||||
|
||||
📖 [Recover](https://docs.gofiber.io/api/middleware/recover)
|
||||
|
|
|
@ -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)
|
||||
- دارای [Template engines](https://github.com/gofiber/template) اختصاصی
|
||||
- [پشتیبانی از وب سوکت](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)
|
||||
- ترجمه در [15 زبان](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>
|
||||
|
||||
### Recover middleware
|
||||
|
|
|
@ -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)
|
||||
- [Template engines](https://github.com/gofiber/template)
|
||||
- [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)
|
||||
- Available in [15 languages](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](https://docs.gofiber.io/api/middleware/recover)
|
||||
|
|
|
@ -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://docs.gofiber.io/middleware#template)
|
||||
- [תמיכה ב-WebSocket](https://github.com/gofiber/websocket)
|
||||
- [Server-Sent events](https://github.com/gofiber/recipes/tree/master/sse)
|
||||
- [הגבלת קצבים ובקשות](https://docs.gofiber.io/api/middleware/limiter)
|
||||
- Available in [12 languages](https://docs.gofiber.io/)
|
||||
- והרבה יותר, [חקור את Fiber](https://docs.gofiber.io/)
|
||||
|
@ -592,6 +593,51 @@ func main() {
|
|||
|
||||
</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 של התאוששות
|
||||
|
||||
📖 [התאוששות](https://docs.gofiber.io/api/middleware/recover)
|
||||
|
|
|
@ -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)
|
||||
- [Template engines](https://github.com/gofiber/template)
|
||||
- [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)
|
||||
- Tersedia dalam [15 bahasa](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](https://docs.gofiber.io/api/middleware/recover)
|
||||
|
|
|
@ -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)
|
||||
- [Template engine](https://github.com/gofiber/template)
|
||||
- [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)
|
||||
- Disponible in [15 lingue](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](https://docs.gofiber.io/api/middleware/recover)
|
||||
|
|
|
@ -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)なサーバーサイドプログラミング
|
||||
- [Template engines](https://github.com/gofiber/template)
|
||||
- [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)
|
||||
- [15 ヶ国語](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](https://docs.gofiber.io/api/middleware/recover)
|
||||
|
|
|
@ -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) 서버 사이드 프로그래밍
|
||||
- [Template engines](https://github.com/gofiber/template)
|
||||
- [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)
|
||||
- Available in [15 languages](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](https://docs.gofiber.io/api/middleware/recover)
|
||||
|
|
|
@ -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
|
||||
- [Template engines](https://github.com/gofiber/template)
|
||||
- [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)
|
||||
- Vertaald in [15 talen](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](https://docs.gofiber.io/api/middleware/recover)
|
||||
|
|
|
@ -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
|
||||
- [Templates](https://github.com/gofiber/template)
|
||||
- [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)
|
||||
- Disponível em [15 línguas](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
|
||||
|
||||
📖 [Recover](https://docs.gofiber.io/api/middleware/recover)
|
||||
|
|
|
@ -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) программирование на стороне сервера
|
||||
- [Template engines](https://github.com/gofiber/template)
|
||||
- [Поддержка 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)
|
||||
- Документация доступна на [15 языках](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](https://docs.gofiber.io/api/middleware/recover)
|
||||
|
|
|
@ -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
|
||||
- [Template engines](https://github.com/gofiber/template)
|
||||
- [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)
|
||||
- ترجم الى [15 لغة أخرى](https://docs.gofiber.io/)
|
||||
- وأكثر بكثير, [استكشف Fiber](https://docs.gofiber.io/)
|
||||
|
@ -556,6 +557,51 @@ func main() {
|
|||
|
||||
</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](https://docs.gofiber.io/api/middleware/recover)
|
||||
|
|
|
@ -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
|
||||
- [Template engines](https://github.com/gofiber/template)
|
||||
- [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)
|
||||
- [15 dilde](https://docs.gofiber.io/) mevcut
|
||||
- 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ı
|
||||
|
||||
📖 [Recover](https://docs.gofiber.io/api/middleware/recover)
|
||||
|
|
|
@ -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://github.com/gofiber/template)
|
||||
- [WebSocket 支持](https://github.com/gofiber/websocket)
|
||||
- [Server-Sent events](https://github.com/gofiber/recipes/tree/master/sse)
|
||||
- [频率限制](https://docs.gofiber.io/api/middleware/limiter)
|
||||
- [15 种语言](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)中间件
|
||||
|
||||
📖 [Recover](https://docs.gofiber.io/api/middleware/recover)
|
||||
|
|
|
@ -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://github.com/gofiber/template)
|
||||
- 支援[WebSocket](https://github.com/gofiber/websocket)
|
||||
- [Server-Sent events](https://github.com/gofiber/recipes/tree/master/sse)
|
||||
- 支援[限速](https://docs.gofiber.io/api/middleware/limiter)
|
||||
- 被翻譯成[15種語言](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](https://docs.gofiber.io/api/middleware/recover)
|
||||
|
|
Loading…
Reference in New Issue