2017-08-25 05:40:04 +00:00
|
|
|
package jsonrpc
|
|
|
|
|
|
|
|
import (
|
|
|
|
gws "git.loafle.net/overflow/overflow_gateway_websocket"
|
|
|
|
)
|
|
|
|
|
|
|
|
type (
|
2017-08-28 07:59:22 +00:00
|
|
|
OnRequestFunc func(soc gws.Socket, method string, params []string) (interface{}, error)
|
|
|
|
OnNotifyFunc func(soc gws.Socket, method string, params []string) error
|
2017-08-25 05:40:04 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// ClientOptions is configuration of the websocket server
|
|
|
|
type Options struct {
|
|
|
|
OnRequest OnRequestFunc
|
|
|
|
OnNotify OnNotifyFunc
|
|
|
|
}
|
|
|
|
|
|
|
|
// Validate validates the configuration
|
|
|
|
func (o *Options) Validate() *Options {
|
|
|
|
if o.OnRequest == nil {
|
2017-08-28 07:59:22 +00:00
|
|
|
o.OnRequest = func(soc gws.Socket, method string, params []string) (interface{}, error) {
|
2017-08-25 05:40:04 +00:00
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if o.OnNotify == nil {
|
2017-08-28 07:59:22 +00:00
|
|
|
o.OnNotify = func(soc gws.Socket, method string, params []string) error {
|
2017-08-25 05:40:04 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return o
|
|
|
|
}
|