docs: improve test coverage and update CI configurations
- Update badge text from "Build Status" to "Run Tests" - Change code block language from unspecified to `sh` Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
# Server-Sent Events
|
# Server-Sent Events
|
||||||
|
|
||||||
[](https://pkg.go.dev/github.com/gin-contrib/sse)
|
[](https://pkg.go.dev/github.com/gin-contrib/sse)
|
||||||
[](https://github.com/gin-contrib/sse/actions/workflows/go.yml)
|
[](https://github.com/gin-contrib/sse/actions/workflows/go.yml)
|
||||||
[](https://codecov.io/gh/gin-contrib/sse)
|
[](https://codecov.io/gh/gin-contrib/sse)
|
||||||
[](https://goreportcard.com/report/github.com/gin-contrib/sse)
|
[](https://goreportcard.com/report/github.com/gin-contrib/sse)
|
||||||
|
|
||||||
@@ -16,25 +16,26 @@ Server-sent events (SSE) is a technology where a browser receives automatic upda
|
|||||||
import "github.com/gin-contrib/sse"
|
import "github.com/gin-contrib/sse"
|
||||||
|
|
||||||
func httpHandler(w http.ResponseWriter, req *http.Request) {
|
func httpHandler(w http.ResponseWriter, req *http.Request) {
|
||||||
// data can be a primitive like a string, an integer or a float
|
// data can be a primitive like a string, an integer or a float
|
||||||
sse.Encode(w, sse.Event{
|
sse.Encode(w, sse.Event{
|
||||||
Event: "message",
|
Event: "message",
|
||||||
Data: "some data\nmore data",
|
Data: "some data\nmore data",
|
||||||
})
|
})
|
||||||
|
|
||||||
// also a complex type, like a map, a struct or a slice
|
// also a complex type, like a map, a struct or a slice
|
||||||
sse.Encode(w, sse.Event{
|
sse.Encode(w, sse.Event{
|
||||||
Id: "124",
|
Id: "124",
|
||||||
Event: "message",
|
Event: "message",
|
||||||
Data: map[string]interface{}{
|
Data: map[string]interface{}{
|
||||||
"user": "manu",
|
"user": "manu",
|
||||||
"date": time.Now().Unix(),
|
"date": time.Now().Unix(),
|
||||||
"content": "hi!",
|
"content": "hi!",
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
```
|
|
||||||
|
```sh
|
||||||
event: message
|
event: message
|
||||||
data: some data\\nmore data
|
data: some data\\nmore data
|
||||||
|
|
||||||
@@ -49,7 +50,8 @@ data: {"content":"hi!","date":1431540810,"user":"manu"}
|
|||||||
```go
|
```go
|
||||||
fmt.Println(sse.ContentType)
|
fmt.Println(sse.ContentType)
|
||||||
```
|
```
|
||||||
```
|
|
||||||
|
```sh
|
||||||
text/event-stream
|
text/event-stream
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user