Documentation ¶
Index ¶
- Constants
- Variables
- func DefaultMux(s *HTTPServer, muxOpts MuxOptions) *http.ServeMux
- func HTTPServerConfigure(setter config.Setter) error
- func HTTPServerPlugin(n *node.Node, getter config.Getter) (server.Server, error)
- func New(n *node.Node, config *Config) (server.Server, error)
- func NewSockJSHandler(s *HTTPServer, sockjsPrefix string, sockjsOpts sockjs.Options) http.Handler
- type Config
- type HTTPServer
- func (s *HTTPServer) APIHandler(w http.ResponseWriter, r *http.Request)
- func (s *HTTPServer) AdminWebsocketHandler(w http.ResponseWriter, r *http.Request)
- func (s *HTTPServer) AuthHandler(w http.ResponseWriter, r *http.Request)
- func (s *HTTPServer) Logged(h http.Handler) http.Handler
- func (s *HTTPServer) RawWebsocketHandler(w http.ResponseWriter, r *http.Request)
- func (s *HTTPServer) Run() error
- func (s *HTTPServer) Shutdown() error
- func (s *HTTPServer) WrapShutdown(h http.Handler) http.Handler
- type HandlerFlag
- type MuxOptions
Constants ¶
const ( AdminWebsocketReadBufferSize = 1024 AdminWebsocketWriteBufferSize = 1024 )
const (
// CloseStatus is status code set when closing client connections.
CloseStatus = 3000
)
Variables ¶
var DefaultConfig = &Config{}
DefaultConfig is Config initialized with default values for all fields.
var DefaultMuxOptions = MuxOptions{ HandlerFlags: HandlerRawWS | HandlerSockJS | HandlerAPI | HandlerAdmin, SockjsOptions: sockjs.DefaultOptions, }
DefaultMuxOptions contain default SockJS options.
Functions ¶
func DefaultMux ¶
func DefaultMux(s *HTTPServer, muxOpts MuxOptions) *http.ServeMux
DefaultMux returns a mux including set of default handlers for Centrifugo server.
func HTTPServerConfigure ¶
func HTTPServerPlugin ¶
func NewSockJSHandler ¶
NewSockJSHandler returns SockJS handler bind to sockjsPrefix url prefix. SockJS handler has several handlers inside responsible for various tasks according to SockJS protocol.
Types ¶
type Config ¶
type Config struct { // Web enables admin web interface. Web bool `json:"web"` // WebPath WebPath string `json:"web_path"` // HTTPAddress HTTPAddress string `json:"http_address"` // HTTPPrefix HTTPPrefix string `json:"http_prefix"` // HTTPPort HTTPPort string `json:"http_port"` // HTTPAdminPort HTTPAdminPort string `json:"http_admin_port"` // HTTPAPIPort HTTPAPIPort string `json:"http_api_port"` // SSL enables builtin https server. SSL bool `json:"ssl"` // SSLCert is path to SSL certificate file. SSLCert string `json:"ssl_cert"` // SSLKey is path to SSL key file. SSLKey string `json:"ssl_key"` // SockjsURL is a custom SockJS library url to use in iframe transports. SockjsURL string `json:"sockjs_url"` // SockjsHeartbeatDelay allows to specify custom SockJS server to client heartbeat interval. // Starting from Centrifugo 1.6.0 we don't use it (i.e. set it 0) as we send pings from // client to server. But if someone wants old behaviour then it's possible to turn off ping // on client side and set this option to something reasonable (25 seconds for example). SockjsHeartbeatDelay int `json:"sockjs_heartbeat_delay"` // WebsocketCompression allows to enable websocket permessage-deflate // compression support for raw websocket connections. It does not guarantee // that compression will be used - i.e. it only says that Centrifugo will // try to negotiate it with client. WebsocketCompression bool `json:"websocket_compression"` // WebsocketCompressionMinSize allows to set minimal limit in bytes for message to use // compression when writing it into client connection. By default it's 0 - i.e. all messages // will be compressed when WebsocketCompression enabled and compression negotiated with client. WebsocketCompressionMinSize int `json:"websocket_compression_min_size"` // WebsocketReadBufferSize is a parameter that is used for raw websocket Upgrader. // If set to zero reasonable default value will be used. WebsocketReadBufferSize int `json:"websocket_read_buffer_size"` // WebsocketWriteBufferSize is a parameter that is used for raw websocket Upgrader. // If set to zero reasonable default value will be used. WebsocketWriteBufferSize int `json:"websocket_write_buffer_size"` }
Config contains Application configuration options.
type HTTPServer ¶
func (*HTTPServer) APIHandler ¶
func (s *HTTPServer) APIHandler(w http.ResponseWriter, r *http.Request)
APIHandler is responsible for receiving API commands over HTTP.
func (*HTTPServer) AdminWebsocketHandler ¶
func (s *HTTPServer) AdminWebsocketHandler(w http.ResponseWriter, r *http.Request)
AdminWebsocketHandler handles admin websocket connections.
func (*HTTPServer) AuthHandler ¶
func (s *HTTPServer) AuthHandler(w http.ResponseWriter, r *http.Request)
AuthHandler allows to get admin web interface token.
func (*HTTPServer) Logged ¶
func (s *HTTPServer) Logged(h http.Handler) http.Handler
Logged middleware logs request.
func (*HTTPServer) RawWebsocketHandler ¶
func (s *HTTPServer) RawWebsocketHandler(w http.ResponseWriter, r *http.Request)
RawWebsocketHandler called when new client connection comes to raw Websocket endpoint.
func (*HTTPServer) Run ¶
func (s *HTTPServer) Run() error
func (*HTTPServer) Shutdown ¶
func (s *HTTPServer) Shutdown() error
func (*HTTPServer) WrapShutdown ¶
func (s *HTTPServer) WrapShutdown(h http.Handler) http.Handler
WrapShutdown will return an http Handler. If Application in shutdown it will return http.StatusServiceUnavailable.
type HandlerFlag ¶
type HandlerFlag int
HandlerFlag is a bit mask of handlers that must be enabled in mux.
const ( // HandlerRawWS enables Raw Websocket handler. HandlerRawWS HandlerFlag = 1 << iota // HandlerSockJS enables SockJS handler. HandlerSockJS // HandlerAPI enables API handler. HandlerAPI // HandlerAdmin enables admin handlers - admin websocket, web interface endpoints. HandlerAdmin // HandlerDebug enables debug handlers. HandlerDebug )
func (HandlerFlag) String ¶
func (flags HandlerFlag) String() string
type MuxOptions ¶
type MuxOptions struct { Prefix string Admin bool Web bool WebPath string WebFS http.FileSystem SockjsOptions sockjs.Options HandlerFlags HandlerFlag }
MuxOptions contain various options for DefaultMux.