-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2808201
commit 58b88a3
Showing
2 changed files
with
65 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
[2024-11-08 20:07:57] ERROR : server listening | ||
[2024-11-08 20:10:06] ERROR : server listening | ||
[2024-11-08 20:11:07] ERROR : server listening | ||
[2024-11-08 20:35:48] ERROR : strating server | ||
[2024-11-08 20:35:48] INFO : SERVER LISTENING ON PORT : 8080 | ||
[2024-11-08 20:49:38] INFO : SIGNING YOU UPPP | ||
[2024-11-08 20:49:39] ERROR : Creating User: table Users has no column named updated_at | ||
[2024-11-08 20:51:49] INFO : SIGNING YOU UPPP | ||
[2024-11-08 20:51:50] ERROR : Creating User: no such function: gen_random_uuid | ||
[2024-11-08 21:10:54] INFO : SIGNING YOU UPPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package main | ||
|
||
import "github.com/gorilla/websocket" | ||
var upgrader = websocket.Upgrader{ | ||
ReadBufferSize: 1024, | ||
WriteBufferSize: 1024, | ||
} | ||
type Client struct { | ||
hub *Hub | ||
// The websocket connection. | ||
conn *websocket.Conn | ||
// Buffered channel of outbound messages. | ||
send chan []byte | ||
} | ||
|
||
type Hub struct { | ||
clients map[*Client]bool | ||
register chan *Client | ||
unregister chan *Client | ||
broadcast chan []byte | ||
} | ||
|
||
func newHub() *Hub { | ||
return &Hub{ | ||
broadcast: make(chan []byte), | ||
clients: make(map[*Client]bool), | ||
register: make(chan *Client), | ||
unregister: make(chan *Client), | ||
} | ||
} | ||
|
||
func (h *Hub) run() { | ||
|
||
for { | ||
select { | ||
case client := <-h.register: | ||
h.clients[client] = true | ||
|
||
case client := <-h.unregister: | ||
if _, ok := h.clients[client]; ok { | ||
delete(h.clients, client) | ||
close(client.send) | ||
} | ||
case message := <-h.broadcast: | ||
for client := range h.clients { | ||
select { | ||
case client.send <- message: | ||
default: | ||
close(client.send) | ||
delete(h.clients, client) | ||
} | ||
} | ||
} | ||
} | ||
} |