Add standard library example

This commit is contained in:
Ola
2022-11-18 19:12:41 +01:00
parent c8e1a31504
commit ad618987a1
4 changed files with 83 additions and 8 deletions
+7 -8
View File
@@ -1,26 +1,25 @@
package main
import (
"github.com/gin-gonic/gin"
"github.com/olahol/melody"
"net/http"
"github.com/olahol/melody"
)
func main() {
r := gin.Default()
m := melody.New()
r.GET("/", func(c *gin.Context) {
http.ServeFile(c.Writer, c.Request, "index.html")
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
http.ServeFile(w, r, "index.html")
})
r.GET("/ws", func(c *gin.Context) {
m.HandleRequest(c.Writer, c.Request)
http.HandleFunc("/ws", func(w http.ResponseWriter, r *http.Request) {
m.HandleRequest(w, r)
})
m.HandleMessage(func(s *melody.Session, msg []byte) {
m.Broadcast(msg)
})
r.Run(":5000")
http.ListenAndServe(":5000", nil)
}