Documentation
¶
Index ¶
- Constants
- Variables
- func DefaultIDGenerator(r *http.Request) string
- func New(cfg *Config) *webds
- type Config
- func (c *Config) BinaryMessages() bool
- func (c *Config) Ctx() context.Context
- func (c *Config) MsgSerializer() *message.Serializer
- func (c *Config) PingPeriod() time.Duration
- func (c *Config) ReadBufferSize() int64
- func (c *Config) ReadTimeout() time.Duration
- func (c *Config) Validate()
- func (c *Config) Webds() core.Webds
- type ConnectionFunc
Constants ¶
View Source
const ( // DefaultWebsocketWriteTimeout 0, no timeout DefaultWebsocketWriteTimeout = 0 // DefaultWebsocketReadTimeout 0, no timeout DefaultWebsocketReadTimeout = 0 // DefaultWebsocketPongTimeout 60 * time.Second DefaultWebsocketPongTimeout = 60 * time.Second // DefaultWebsocketPingPeriod (DefaultPongTimeout * 9) / 10 DefaultWebsocketPingPeriod = (DefaultWebsocketPongTimeout * 9) / 10 // DefaultWebsocketMaxMessageSize 1024 DefaultWebsocketMaxMessageSize = 1024 // DefaultWebsocketReadBufferSize 4096 DefaultWebsocketReadBufferSize = 4096 // DefaultWebsocketWriterBufferSize 4096 DefaultWebsocketWriterBufferSize = 4096 )
View Source
const (
Version = "v0.2.5"
)
Variables ¶
Functions ¶
func DefaultIDGenerator ¶ added in v0.2.0
DefaultIDGenerator returns a random unique for a new conn. Used when cfg.IDGenerator is nil.
Types ¶
type Config ¶ added in v0.2.0
type Config struct {
// the server id
ID string
// IDGenerator used to create (and later on, set)
// an ID for each incoming websocket connections (clients).
// The request is an input parameter which you can use to generate the ID (from headers for example).
// If empty then the ID is generated by DefaultIDGenerator: randomString(64)
IDGenerator func(r *http.Request) string
// record the url address of the superior cluster
SuperiorMaster []string
// record the url address of the lateral cluster
LateralMaster []string
EnableCluster bool
// MsgPrefix is the prefix of the underline websocket events that are being established under the hoods.
// This prefix is visible only to the javascript side (code) and it has nothing to do
// with the message that the end-user receives.
// Do not change it unless it is absolutely necessary.
//
// If empty then defaults to []byte("ws").
MsgPrefix []byte
// Error is the function that will be fired if any client couldn't upgrade the HTTP conn
// to a websocket conn, a handshake error.
Error func(w http.ResponseWriter, r *http.Request, status int, reason error)
// CheckOrigin a function that is called right before the handshake,
// if returns false then that client is not allowed to connect with the websocket server.
CheckOrigin func(r *http.Request) bool
// HandshakeTimeout specifies the duration for the handshake to complete.
HandshakeTimeout time.Duration
// WriteTimeout time allowed to write a message to the conn.
// 0 means no timeout.
// Default value is 0
WriteTimeout time.Duration
// EnableCompression specify if the server should attempt to negotiate per
// message compression (RFC 7692). Setting this value to true does not
// guarantee that compression will be supported. Currently only "no context
// takeover" modes are supported.
//
// Defaults to false and it should be remain as it is, unless special requirements.
EnableCompression bool
// Subprotocols specifies the server's supported protocols in order of
// preference. If this field is set, then the Upgrade method negotiates a
// subprotocol by selecting the first match in this list with a protocol
// requested by the client.
Subprotocols []string
// contains filtered or unexported fields
}
Config the websocket server configuration all of these are optional.
func (*Config) BinaryMessages ¶ added in v0.2.0
func (*Config) MsgSerializer ¶ added in v0.2.5
func (c *Config) MsgSerializer() *message.Serializer
func (*Config) PingPeriod ¶ added in v0.2.0
func (*Config) ReadBufferSize ¶ added in v0.2.0
func (*Config) ReadTimeout ¶ added in v0.2.0
type ConnectionFunc ¶ added in v0.2.0
type ConnectionFunc func(core.Connection) error
Click to show internal directories.
Click to hide internal directories.
