-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
39 lines (31 loc) · 826 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package main
import (
"log"
"github.com/gofiber/contrib/websocket"
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/cors"
)
func main() {
InitialiseRedis()
log.Println("Redis has been Initialised")
app := fiber.New()
app.Use(cors.New())
app.Use("/ws", func(c *fiber.Ctx) error {
if websocket.IsWebSocketUpgrade(c) {
c.Locals("allowed", true)
return c.Next()
}
return fiber.ErrUpgradeRequired
})
ws := app.Group("/ws")
ws.Get("/heartbeat", func(c *fiber.Ctx) error {
return c.JSON(fiber.Map{
"status": "Running",
"redis_connection": RedisConnected(),
})
})
ws.Get("/format", websocket.New(fileFormatterController()))
ws.Get("/compile", websocket.New(compilerController()))
app.Listen(":" + wsPort)
log.Println("App is listening on Port:", wsPort)
}