commit 52f61b0bd14eef5267b96703696332afcab02259 Author: Lucas Winther Date: Sat Jul 17 21:24:58 2021 +0200 Initial commit diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..73f69e0 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml +# Editor-based HTTP Client requests +/httpRequests/ diff --git a/.idea/goTestProj.iml b/.idea/goTestProj.iml new file mode 100644 index 0000000..c956989 --- /dev/null +++ b/.idea/goTestProj.iml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..750a81d --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/main.go b/main.go new file mode 100644 index 0000000..e83b3e5 --- /dev/null +++ b/main.go @@ -0,0 +1,26 @@ +package main + +import ( + "github.com/gin-gonic/gin" + "gopkg.in/olahol/melody.v1" + "net/http" +) + +func main() { + r := gin.Default() + m := melody.New() + + r.GET("/", func(c *gin.Context) { + http.ServeFile(c.Writer, c.Request, "index.html") + }) + + r.GET("/ws", func(c *gin.Context) { + m.HandleRequest(c.Writer, c.Request) + }) + + m.HandleMessage(func(s *melody.Session, msg []byte) { + m.Broadcast(msg) + }) + + r.Run(":5000") +} \ No newline at end of file