如何将所有goroutine中的数据/事件发布到Web服务?

My Project is a TCP server (not http) and works something like this

main() {

for {
    conn, err := listener.Accept()
    go handleClient(conn, &Client{})
}

I usually have hundreds of clients connecting at the same time

inside handleconnection, my "events" look something like this

IP
1.2.3.4 client connect
1.2.3.4 client send command XYZ
1.2.3.4 client send data
server send data to 1.2.3.4
1.2.3.4 client send command XYZ
[repeated N times]

For each of these events, i want to create a "real time view" of events accross my goroutines and all the clients. Basically, you could say its a status for each connecting client

something that would looke like

client IP   status          time    total KB    
1.2.3.4     connect         1       0
5.6.7.8     send data       14      22
10.10.10.10 recieving data  22      11      

I have all the information i need in each connections (handleconn) but i have no idea how to make this available for a webservice.

Problem: How do i make all of these event status msg availble for a function, or another goroutine or something which can collect everything from all goroutines and publish it?

Do i need to use channels for this? or another go routine which is launched only one time and can recieve data using channels

Or a completely other approach to collect and publish the data?

disclaimer: Im very new to programming and golang. Just an old dude trying to learn

There is a package in the Go library that is designed for this use, expvar. According to the docs, it already does all the wrapping as web service for you:

http://golang.org/pkg/expvar/

You can also have a type Supervisor which will keep a registry of all your Connection.

Each Connection will have some properties such as ClientIP, Status, Time and TotalKB.

When there is a new connection, instantiate a new Connection, add it to the supervisor's registry and spawn a Go routine. The go routine will update its own informations depending on what's going on.

From the Supervisor you have access to all the Connections, and you can therefore display what you want on the terminal or web. It's up to you.

To keep the registry up-to-date, you can use Tomb, which is really useful when you have to track go routines.

I hope it will help