Documentation
¶
Index ¶
- func Broadcast(topic, message string) error
- func CallRpc(topic string, message interface{}, callback func(RpcResult))
- func ClientRun(addr string)
- func Close()
- func Cmd(cmd ...string)
- func Delay(topic, message string, delay int) error
- func InitFromCurrentDir() error
- func InitFromEnv() error
- func InitWithOptions(opts *ConfigOptions) error
- func InitWithProjectConfig(projectConfigPath string) error
- func InitWithWorkingDir(configName string) error
- func Publish(topic, message string) error
- func ReleaseLock(lock Lock)
- func RpcSubscribe(topic string, handler func(Rpc) RpcResult)
- func RpcWithTimeout(topic string, message interface{}, timeout time.Duration, ...)
- func Subscribe(topic string, callback func(string))
- func Timer(topic string, callback func())
- func ToJSON(message interface{}) (string, error)
- func Unsubscribe(topic string)
- type Client
- type Config
- type ConfigOptions
- type Lock
- type Rpc
- type RpcResult
- type RpcRet
- type ZHubClient
- func (c *ZHubClient) Broadcast(topic string, message string) error
- func (c *ZHubClient) Close()
- func (c *ZHubClient) Cmd(cmd ...string)
- func (c *ZHubClient) Delay(topic string, message string, delay int) error
- func (c *ZHubClient) Lock(key string, duration int) Lock
- func (c *ZHubClient) Publish(topic string, message string) error
- func (c *ZHubClient) Rpc(topic string, message interface{}, back func(res RpcResult))
- func (c *ZHubClient) RpcSubscribe(topic string, fun func(Rpc) RpcResult)
- func (c *ZHubClient) RpcWithTimeout(topic string, message interface{}, timeout time.Duration, ...)
- func (c *ZHubClient) Start() error
- func (c *ZHubClient) Subscribe(topic string, fun func(v string))
- func (c *ZHubClient) Timer(topic string, fun func())
- func (c *ZHubClient) Unlock(l Lock)
- func (c *ZHubClient) Unsubscribe(topic string)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func InitWithProjectConfig ¶
InitWithProjectConfig 使用项目配置文件初始化
func InitWithWorkingDir ¶
InitWithWorkingDir 使用工作目录下的配置文件
func ReleaseLock ¶
func ReleaseLock(lock Lock)
func RpcSubscribe ¶
func RpcWithTimeout ¶
func Unsubscribe ¶
func Unsubscribe(topic string)
Types ¶
type Client ¶
type Client struct {
*ZHubClient
// contains filtered or unexported fields
}
Client 客户端包装器
type Config ¶
type Config struct {
Appname string `mapstructure:"appname"`
Addr string `mapstructure:"addr"`
Groupid string `mapstructure:"groupid"`
Auth string `mapstructure:"auth"`
}
Config zhub客户端配置
func LoadConfigFromProject ¶
LoadConfigFromProject 从项目配置文件加载(推荐方式)
func LoadConfigWithOptions ¶
func LoadConfigWithOptions(opts *ConfigOptions) (*Config, error)
LoadConfigWithOptions 使用选项加载配置
type ConfigOptions ¶
type ConfigOptions struct {
ConfigPath string // 配置文件路径
ConfigName string // 配置文件名 (默认: "app")
ConfigType string // 配置文件类型 (默认: "yml")
ConfigKey string // 配置节点名 (默认: "zhub")
EnvPrefix string // 环境变量前缀 (可选)
}
ConfigOptions 配置加载选项
type Lock ¶
type Lock struct {
Key string // lock Key
Value string // lock Value
// contains filtered or unexported fields
}
Lock 分布式锁
func AcquireLock ¶
type Rpc ¶
type Rpc struct {
Ruk string `json:"ruk"`
Topic string `json:"topic"`
Value string `json:"value"`
Ch chan int `json:"-"` //请求返回标记
RpcResult RpcResult `json:"-"`
}
Rpc RPC 请求结构
type RpcResult ¶
type RpcResult struct {
Ruk string `json:"ruk"`
Retcode int `json:"retcode"`
Retinfo string `json:"retinfo"`
Result any `json:"result"`
}
RpcResult RPC 返回结果
func (*RpcResult) GetRetcode ¶
func (*RpcResult) GetRetinfo ¶
type ZHubClient ¶
type ZHubClient struct {
Appname string // local appname
Addr string // host:port
Groupid string // client group id
Auth string
// contains filtered or unexported fields
}
ZHubClient zhub客户端
func (*ZHubClient) Close ¶
func (c *ZHubClient) Close()
func (*ZHubClient) Delay ¶
func (c *ZHubClient) Delay(topic string, message string, delay int) error
func (*ZHubClient) Publish ¶
func (c *ZHubClient) Publish(topic string, message string) error
Publish 发布消息
func (*ZHubClient) Rpc ¶
func (c *ZHubClient) Rpc(topic string, message interface{}, back func(res RpcResult))
func (*ZHubClient) RpcSubscribe ¶
func (c *ZHubClient) RpcSubscribe(topic string, fun func(Rpc) RpcResult)
RpcSubscribe rpc subscribe
func (*ZHubClient) RpcWithTimeout ¶
func (c *ZHubClient) RpcWithTimeout(topic string, message interface{}, timeout time.Duration, back func(res RpcResult))
func (*ZHubClient) Subscribe ¶
func (c *ZHubClient) Subscribe(topic string, fun func(v string))
Subscribe subscribe topic
func (*ZHubClient) Timer ¶
func (c *ZHubClient) Timer(topic string, fun func())
func (*ZHubClient) Unlock ¶
func (c *ZHubClient) Unlock(l Lock)
func (*ZHubClient) Unsubscribe ¶
func (c *ZHubClient) Unsubscribe(topic string)
Click to show internal directories.
Click to hide internal directories.