new json_data model

This commit is contained in:
Adrian Zuercher
2025-05-04 22:21:12 +02:00
parent 7d6b09cf11
commit 5203fb8543
13 changed files with 79 additions and 45 deletions

View File

@@ -12,11 +12,13 @@ import (
json_dataModels "github.com/tecamino/tecamino-json_data/models"
)
// serves as connection handler of websocket
type Connections struct {
sync.RWMutex
Clients Clients
}
// initaiates new conections with client map
func NewConnections() *Connections {
return &Connections{
Clients: NewClients(),
@@ -36,10 +38,11 @@ func (c *Connections) DisconnectWsConnection(id string, code websocket.StatusCod
c.Clients.DisconnectWsConnection(id, code, reason)
}
// sends json response to client
func (c *Connections) SendResponse(id string, r *json_dataModels.Response) error {
client, ok := c.Clients[id]
if !ok {
return fmt.Errorf("client not found for id " + id)
return fmt.Errorf("client not found for id %s", id)
}
b, err := json.Marshal(r)