1 Star 0 Fork 0

siliworks / common-package

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
options.go 2.87 KB
一键复制 编辑 原始数据 按行查看 历史
545403892 提交于 2023-06-06 00:08 . init
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
}
1
https://gitee.com/siliworks/common-package.git
git@gitee.com:siliworks/common-package.git
siliworks
common-package
common-package
v1.0.3

搜索帮助

53164aa7 5694891 3bd8fe86 5694891