A lightweight extendable Go WebSocket-framework with client library.
The project can be considered dead. There has been no development in recent years. It is still available on github for research and archiving purposes.
Golem is available under the Apache License, Version 2.0
go get github.com/trevex/golem
A client is also available and heavily used in the examples. More information on how the client is used can be found in the client repository.
Server:
type Hello struct {
From string `json:"from"`
}
type Answer struct {
Msg string `json:"msg"`
}
func hello(conn *golem.Connection, data *Hello) {
conn.Emit("answer", &Answer{"Thanks, "+ data.From + "!"})
}
func main() {
myrouter := golem.NewRouter()
myrouter.On("hello", hello)
http.HandleFunc("/ws", myrouter.Handler())
http.ListenAndServe(":8080", nil)
}
Client:
var conn = new golem.Connection("ws://127.0.0.1:8080/ws", true);
conn.on("answer", function(data) {
console.log("Answer: "+data.msg);
});
conn.on("open", function() {
conn.emit("hello", { from: "Client" });
});
Output in client console would be Thanks, Client!
.
The documentation is provided via godoc.
More informations and insights can be found on the wiki page along with a tutorial series to learn how to use golem:
- Getting started
- Using rooms
- Building a Chat application
- Handshake authorisation using Sessions
- Using flash as WebSocket fallback
- Custom protocol using BSON
- Using an extended connection type
Several examples are available in the example repository. To use them simply checkout the repository and make sure you installed (go get) golem before. A more detailed guide on how to use them is located in their repository.
- v0.1.0
- Basic API layout and documentation
- v0.2.0
- Evented communication system and routing
- Basic room implementation (lobbies renamed to rooms for clarity)
- v0.3.0
- Protocol extensions through Parsers
- Room manager for collections of rooms
- v0.4.0
- Protocol interchangable
- Several bugfixes
- Client up-to-date
- v0.4.2
- Connection type can be extended
- Close added to connection
- v0.4.3
- RoomManager emiting create- and remove-events (remove if room has insufficient users)
- v0.4.4
- RoomManager manages set of connection dependent options, see
example_chat_options.go
- Router provides OnConnect callback
- RoomManager manages set of connection dependent options, see
- Gary Burd (for the great WebSocket protocol implementation and insights through his examples)
- Andrew Gallant (for help on golang-nuts mailing list)
- Kortschak (for help on golang-nuts mailing list)
- Verbose and configurable logging
- Testing