move websocket vars and const to vars.go

This commit is contained in:
Sebastian Mark 2024-11-21 09:33:29 +01:00
parent 2d469a0b86
commit 68b5784255
3 changed files with 18 additions and 11 deletions

View file

@ -2,19 +2,13 @@ package websocket
import ( import (
"github.com/gorilla/websocket" "github.com/gorilla/websocket"
"net"
"net/http" "net/http"
"sync"
"time" "time"
"git.smsvc.net/pomodoro/GoTomato/internal/helper" "git.smsvc.net/pomodoro/GoTomato/internal/helper"
"git.smsvc.net/pomodoro/GoTomato/pkg/models" "git.smsvc.net/pomodoro/GoTomato/pkg/models"
) )
// Clients is a map of connected WebSocket clients, where each client is represented by the WebsocketClient struct
var Clients = make(map[net.Addr]*models.WebsocketClient)
var mu sync.Mutex // Mutex to protect access to the Clients map
// Upgrade HTTP requests to WebSocket connections // Upgrade HTTP requests to WebSocket connections
var upgrader = websocket.Upgrader{ var upgrader = websocket.Upgrader{
CheckOrigin: func(r *http.Request) bool { return true }, CheckOrigin: func(r *http.Request) bool { return true },

View file

@ -1,5 +0,0 @@
package websocket
const SEND_TIMEOUT = 10
const STALE_CLIENT_TIMEOUT = 90
const STALE_CHECK_INTERVALL = 30

View file

@ -0,0 +1,18 @@
package websocket
import (
"net"
"sync"
"git.smsvc.net/pomodoro/GoTomato/pkg/models"
)
const SEND_TIMEOUT = 10
const STALE_CLIENT_TIMEOUT = 90
const STALE_CHECK_INTERVALL = 30
// Clients is a map of connected WebSocket clients, where each client is represented by the WebsocketClient struct
var Clients = make(map[net.Addr]*models.WebsocketClient)
// Mutex to protect access to the Clients map
var mu sync.Mutex