Skip to content

Commit

Permalink
👌 chore: update readme.md #2
Browse files Browse the repository at this point in the history
  • Loading branch information
pnguyen215 committed Jul 23, 2023
1 parent 26cb6e5 commit d029f56
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,35 @@
# WsConn

## Example Publish Event
## Example Publish Event

```go
package main

import (
"net/http"
"time"

"github.com/gin-gonic/gin"
"github.com/sivaosorg/govm/wsconnx"
"github.com/sivaosorg/wsconn/wsconn"
)

func main() {
r := gin.Default()
ws := wsconn.NewWebsocket()
s := wsconn.NewWebsocketService(ws)

r.GET("/subscribe", s.SubscribeMessage) // ws://localhost:8081/subscribe
r.POST("/message", func(c *gin.Context) {
var message wsconnx.WsConnMessagePayload
message.SetGenesisTimestamp(time.Now())
if err := c.ShouldBindJSON(&message); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": "Invalid request payload"})
return
}
s.BroadcastMessage(message)
c.JSON(http.StatusOK, gin.H{"message": "Message sent successfully", "data": message})
})
r.Run(":8081")
}
```

0 comments on commit d029f56

Please sign in to comment.