43 lines
888 B
Go
43 lines
888 B
Go
|
package clients
|
||
|
|
||
|
import "time"
|
||
|
|
||
|
const ()
|
||
|
|
||
|
// Options is configuration of the websocket server
|
||
|
type Options struct {
|
||
|
OnRequest func(c Client, method string, params interface{}) (interface{}, error)
|
||
|
OnNotify func(c Client, method string, params interface{}) error
|
||
|
OnDisconnected func(c Client)
|
||
|
|
||
|
MaxMessageSize int64
|
||
|
WriteTimeout time.Duration
|
||
|
ReadTimeout time.Duration
|
||
|
BinaryMessage bool
|
||
|
ReadBufferSize int
|
||
|
WriteBufferSize int
|
||
|
}
|
||
|
|
||
|
// Validate validates the configuration
|
||
|
func (o *Options) Validate() *Options {
|
||
|
|
||
|
if o.OnRequest == nil {
|
||
|
o.OnRequest = func(c Client, method string, params interface{}) (interface{}, error) {
|
||
|
return nil, nil
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if o.OnNotify == nil {
|
||
|
o.OnNotify = func(c Client, method string, params interface{}) error {
|
||
|
return nil
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if o.OnDisconnected == nil {
|
||
|
o.OnDisconnected = func(c Client) {
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return o
|
||
|
}
|