WebSocketServer/main.go

51 lines
933 B
Go

package main
import (
"log"
"os"
"clickandjoin.app/websocketserver/modules/config"
"clickandjoin.app/websocketserver/modules/rabbitmq"
"clickandjoin.app/websocketserver/socketserver"
"github.com/gofiber/fiber/v2"
"github.com/gofiber/websocket/v2"
"github.com/sirupsen/logrus"
)
func init() {
config.LoadConfig()
if config.Cfg.Debug {
logrus.SetLevel(logrus.DebugLevel)
}
logrus.Println("Debug:", config.Cfg.Debug)
go rabbitmq.Init()
}
func main() {
app := fiber.New()
app.Use("/", func(c *fiber.Ctx) error {
// IsWebSocketUpgrade returns true if the client
// requested upgrade to the WebSocket protocol.
if websocket.IsWebSocketUpgrade(c) {
c.Locals("allowed", true)
return c.Next()
}
return fiber.ErrUpgradeRequired
})
go socketserver.RunHub()
socketserver.WebSocketServer(app)
if len(os.Args) < 2 {
log.Fatalln("Please specify port")
}
app.Listen("127.0.0.1:" + os.Args[1])
}