Documentation ¶
Overview ¶
Package gosockjs is an concurrent safe implementation of a SockJS server. The core design principles are described here http://blog.igormihalik.com/2012/12/sockjs-for-go.html and source code can be found on github https://github.com/igm/sockjs-go
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var DefaultConfig = Config{ SockjsUrl: "http://cdn.sockjs.org/sockjs-0.3.4.min.js", Websocket: true, ResponseLimit: 128 * 1024, HeartbeatDelay: time.Duration(25 * time.Second), DisconnectDelay: time.Duration(5 * time.Second), CookieNeeded: false, DecodeFrames: false, }
Default Configuration with 128kB response limit
View Source
var ErrConnectionClosed = errors.New("Connection closed.")
Error variable
Functions ¶
func Install ¶
func Install(baseUrl string, h HandlerFunc, cfg Config) http.Handler
Example ¶
package main import ( "github.com/igm/sockjs-go/sockjs" "net/http" ) func main() { // Echo Handler var handler = func(c sockjs.Conn) { for { msg, err := c.ReadMessage() if err == sockjs.ErrConnectionClosed { return } c.WriteMessage(msg) } } // install echo sockjs in default http handler sockjs.Install("/echo", handler, sockjs.DefaultConfig) http.ListenAndServe(":8080", nil) }
Output:
func NewRouter ¶
func NewRouter(baseUrl string, h HandlerFunc, cfg Config) http.Handler
Creates new http.Handler that can be used in http.ServeMux (e.g. http.DefaultServeMux)
Example ¶
package main import ( "github.com/igm/sockjs-go/sockjs" "net/http" ) func main() { // Echo Handler var handler = func(c sockjs.Conn) { for { msg, err := c.ReadMessage() if err == sockjs.ErrConnectionClosed { return } c.WriteMessage(msg) } } router := sockjs.NewRouter("/echo", handler, sockjs.DefaultConfig) http.Handle("/echo", router) http.ListenAndServe(":8080", nil) }
Output:
Types ¶
type Conn ¶
type Conn interface { // Reads message from the open connection. Or returns error if connection is closed. ReadMessage() ([]byte, error) // Writes message to the open connection. Or returns error if connection is closed. WriteMessage([]byte) (int, error) // Closes open conenction. Or returns error if connection is already closed. Close() error }
Conn is a sockjs data-frame oriented network connection.
type HandlerFunc ¶
type HandlerFunc func(Conn)
Click to show internal directories.
Click to hide internal directories.