a high flexible websocket framwork base on gorilla
monkey is a really simple websoket framwork base on gorilla, which makes you build your app in a simple way
- high flexible API
- as little as possible dependency
- easy to understand
- OnTransportMade
- OnTransportLost
- OnTransportData
- OnPing
- OnPong
generally, you just need to implement Protocol
interface with your business, and then new and run a monkey instance, then it works
1. monkey.New() got a monkey instance with your own protocol
2. new a multiplexes with websocket path and handlers,
3. register protocol with `HandleConnection` in websocket handles
4. start server with your multiplexes(usually is `http.DefaultServeMux`)
go get -u github.com/xlionet/monkey
Echo example, more information in example
func main() {
protocol := &Echo{}
cfg := monkey.NewConfig()
cfg.WSListernPort = 8080
mk := monkey.New(protocol, cfg)
http.HandleFunc("/echo", func(w http.ResponseWriter, r *http.Request) {
err := mk.HandleConnection(w, r)
if err != nil {
log.Fatal(err)
}
})
http.HandleFunc("/", index)
mk.Serve(http.DefaultServeMux)
}