Skip to content

Commit

Permalink
fix: server-sent-event example should use c.Writer.CloseNotify() chan
Browse files Browse the repository at this point in the history
  • Loading branch information
Justin Toman committed Jul 15, 2024
1 parent 0ebcc73 commit ab2e70b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
6 changes: 3 additions & 3 deletions server-sent-event/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ It is Way to send events from server to clients.

Here is Example for SSE with basic authentication using gin.

### How to Run?
## How to Run?

1) Run `` go run main.go ``
1. Run `go run main.go`

2) Open ``http://127.0.0.1:8085`` in browser and authorize with username and password given in main.go and see messages.
2. Open `http://127.0.0.1:8085` in browser and authorize with username and password given in main.go and see messages.
3 changes: 2 additions & 1 deletion server-sent-event/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ func (stream *Event) serveHTTP() gin.HandlerFunc {
// Send new connection to event server
stream.NewClients <- clientChan

defer func() {
go func() {
<-c.Writer.CloseNotify()
// Send closed connection to event server
stream.ClosedClients <- clientChan
}()
Expand Down

0 comments on commit ab2e70b

Please sign in to comment.