I am very new to Go and have found myself working with sockets as my first project. This is a redundant question, but I have failed to understand how to send a websocket update to a specific channel in Go (using Gorilla).
I am using code sample from this link
this method. But failed to modify to send messages to specific channel.
Here is my sample code main.go
func main() {
flag.Parse()
hub := newHub()
go hub.run()
http.HandleFunc("/ws", func(w http.ResponseWriter, r *http.Request) {
fmt.Println(hub)
serveWs(hub, w, r)
})
err := http.ListenAndServe(*addr, nil)
if err != nil {
log.Fatal("ListenAndServe: ", err)
}
}
There is other two files called hub.go and client.go I think hub.go below here something could be done
return &Hub{
broadcast: make(chan []byte),
register: make(chan *Client),
unregister: make(chan *Client),
clients: make(map[*Client]bool),
}
Please suggest what should I change from here? Thanks in advanced.
****UPDATE**
What I am trying to do is I have a socket server written in go. Now suppose we have many clients written in react listening on server with a specific url like wss://abc.com/wss1 or may be wss://abc.com/wss2
Now if client wss1 send a message to server, server will emit this message all clients listening on url wss1 not wss2 and vice versa.
Till now i have been able to do broadcast to all clients irrespective of wss1 or wss2. Hope I made it clear.