Update multichat example
This commit is contained in:
@@ -21,7 +21,7 @@
|
||||
</center>
|
||||
|
||||
<script>
|
||||
var url = "ws://" + window.location.host + window.location.pathname + "/ws";
|
||||
var url = "ws://" + window.location.host + "/ws";
|
||||
var ws = new WebSocket(url);
|
||||
var name = "Guest" + Math.floor(Math.random() * 1000);
|
||||
var channelName = window.location.pathname.split("/")[2];
|
||||
|
||||
+12
-12
@@ -1,25 +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) {
|
||||
if r.URL.Path == "/" {
|
||||
http.ServeFile(w, r, "index.html")
|
||||
return
|
||||
}
|
||||
|
||||
http.ServeFile(w, r, "chan.html")
|
||||
})
|
||||
|
||||
r.GET("/channel/:name", func(c *gin.Context) {
|
||||
http.ServeFile(c.Writer, c.Request, "chan.html")
|
||||
})
|
||||
|
||||
r.GET("/channel/:name/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) {
|
||||
@@ -28,5 +28,5 @@ func main() {
|
||||
})
|
||||
})
|
||||
|
||||
r.Run(":5000")
|
||||
http.ListenAndServe(":5000", nil)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user