0
Fork 0
mirror of https://codeberg.org/SafeTwitch/safetwitch-backend.git synced 2025-01-08 13:50:05 -05:00
safetwitch-backend/routes/root/root.go

27 lines
614 B
Go

package root
import (
"safetwitch-backend/extractor"
"safetwitch-backend/extractor/chat"
"github.com/gin-gonic/gin"
"github.com/gobwas/ws"
)
func Routes(route *gin.Engine) {
auth := route.Group("/")
auth.GET("/", func(context *gin.Context) {
upgradeHeader := context.Request.Header.Get("Upgrade")
if upgradeHeader == "websocket" {
conn, _, _, err := ws.UpgradeHTTP(context.Request, context.Writer)
if err != nil {
context.Error(err)
}
go chat.CreateWebsocketServer(conn, context)
} else {
context.JSON(200, extractor.FormatMessage("SafeTwitch backend running", true))
}
})
}