代码拉取完成,页面将自动刷新
package client
import "time"
type Handle interface {
Send(data map[string]interface{}) error
Run() error
Close()
}
// OnConnectHandler 客户端连接成功后的回调函数
type OnConnectHandler func(Handle)
// OnDisconnectHandler 客户端断开后的回调函数
type OnDisconnectHandler func(Handle, error)
// OnDataHandler 客户端收到数据后的回调函数
type OnDataHandler func(Handle, map[string]interface{}, string)
// OnReconnectHandler sets the function to be called when the client is reconnected.
type OnReconnectHandler func(Handle)
type Options struct {
Address string `json:"address"`
KeepAlive time.Duration `json:"keepalive"`
AuthenticationEnable bool `json:"authenticationEnable"`
AuthenticationKey string `json:"authenticationKey"`
AutoReconnect bool `json:"autoReconnect"`
ReconnectInterval time.Duration `json:"reconnectInterval"`
OnConnect OnConnectHandler
OnDisconnect OnDisconnectHandler
OnData OnDataHandler
OnReconnecting OnReconnectHandler
}
// SetAddress sets the address to be used by the client to connect.
func (o *Options) SetAddress(address string) *Options {
o.Address = address
return o
}
// SetAuthenticationKey sets the key to be used when the client connected and for the first time send data.
func (o *Options) SetAuthenticationKey(authenticationKey string) *Options {
o.AuthenticationKey = authenticationKey
return o
}
// SetAuthenticationEnable sets the function to be called when the client connected and for the first time receives data.
func (o *Options) SetAuthenticationEnable(authenticationEnable bool) *Options {
o.AuthenticationEnable = authenticationEnable
return o
}
// SetAutoReconnect sets the function to be called when the client is reconnected.
func (o *Options) SetAutoReconnect(autoReconnect bool) *Options {
o.AutoReconnect = autoReconnect
return o
}
// SetReconnectInterval sets the interval of reconnection.
func (o *Options) SetReconnectInterval(interval time.Duration) *Options {
o.ReconnectInterval = interval
return o
}
// SetOnConnectHandler sets the function to be called when the client is connected. Both
func (o *Options) SetOnConnectHandler(onConn OnConnectHandler) *Options {
o.OnConnect = onConn
return o
}
// SetOnDisconnectHandler sets the function to be called when the client is disconnected.
func (o *Options) SetOnDisconnectHandler(onLost OnDisconnectHandler) *Options {
o.OnDisconnect = onLost
return o
}
// SetOnDataHandler sets the function to be called when the client receives data.
func (o *Options) SetOnDataHandler(onData OnDataHandler) *Options {
o.OnData = onData
return o
}
// SetOnReconnectHandler sets the function to be called when the client is reconnected.
func (o *Options) SetOnReconnectHandler(onReconnect OnReconnectHandler) *Options {
o.OnReconnecting = onReconnect
return o
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。