修改微信扫码登录 access_token 问题
This commit is contained in:
23
utility/mqtt/mqtt.go
Normal file
23
utility/mqtt/mqtt.go
Normal file
@ -0,0 +1,23 @@
|
||||
package mqtt
|
||||
|
||||
// MqttClient 定义了通用 MQTT 客户端接口
|
||||
type MqttClient interface {
|
||||
// Publish 发布消息到指定 topic
|
||||
Publish(topic string, payload []byte) error
|
||||
// Subscribe 订阅指定 topic,接收回调
|
||||
Subscribe(topic string, handler func(topic string, payload []byte)) error
|
||||
}
|
||||
|
||||
// 全局注册表
|
||||
var clients = make(map[string]MqttClient)
|
||||
|
||||
// Register 注册一个 MQTT 客户端实现
|
||||
func Register(name string, client MqttClient) {
|
||||
clients[name] = client
|
||||
}
|
||||
|
||||
// GetClient 获取已注册的客户端
|
||||
func GetClient(name string) (MqttClient, bool) {
|
||||
client, ok := clients[name]
|
||||
return client, ok
|
||||
}
|
||||
Reference in New Issue
Block a user