实时推送通知golang

I want to implement a real time notification feature in my web application. I am following this example "https://github.com/gorilla/websocket/tree/master/examples/chat". I need the server (hub) to get messages, it needs to push those messages to individual clients based on some form of ID. how can I do this?

From the sample you mentioned:

    case message := <-h.broadcast:
        for client := range h.clients {
            select {
            case client.send <- message:
            default:
                close(client.send)
                delete(h.clients, client)
            }
        }
    }

This is the case where a message is broadcasted to all clients. As you can see it loops over all registered clients and sends the message to every single one of them.

To preserve this functionality we will simply add another case: send to a single client.

    case message := <-h.clientMessage:
        for client := range h.clients {
            if message.ClientID == client.ID {
                select {
                case client.send <- message:
                default:
                    close(client.send)
                    delete(h.clients, client)
                }
            }
        }
    }

This should give you an idea. The rest I leave up to you.

Note: my sample code can be optimised by e.g. using a map[clientID]Client to access the client directly.