/
client.go
62 lines (54 loc) · 1.27 KB
/
client.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// Copyright 2023 Anlity <leo@leocode.net>. All rights reserved.
// Use of this source code is governed by a AGPL v3.0 style
// license that can be found in the LICENSE file.
package vmq
import (
"github.com/anlityli/chatait-free/chatait-public-lib/app/libservice"
"github.com/gogf/gf/os/glog"
"sync"
)
// VmqClient VmqClient
type VmqClient struct {
config *libservice.ConfigPay
apiKey string
host string
}
var vmqClient *VmqClient
var vmqClientOnce sync.Once
// Instance 单例
func Instance() *VmqClient {
vmqClientOnce.Do(func() {
vmqClient = &VmqClient{}
if err := vmqClient.init(); err != nil {
glog.Line().Println("vmqClient init失败:" + err.Error())
}
})
return vmqClient
}
// init 初始化
func (c *VmqClient) init() (err error) {
c.config, err = libservice.Pay.OneConfigPay(1)
if err != nil {
return err
}
for _, item := range c.config.Params {
if item.Param == "apiKey" {
c.apiKey = item.Value
} else if item.Param == "host" {
lastStr := item.Value[len(item.Value)-1:]
if lastStr != "/" {
item.Value = item.Value + "/"
}
c.host = item.Value
}
}
return
}
// GetApiKey 获取通讯密钥
func (c *VmqClient) GetApiKey() string {
return c.apiKey
}
// GetHost 获取host
func (c *VmqClient) GetHost() string {
return c.host
}