-
Notifications
You must be signed in to change notification settings - Fork 30
/
init.go
69 lines (59 loc) · 1.29 KB
/
init.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
63
64
65
66
67
68
69
package nacosRF
import (
"github.com/nacos-group/nacos-sdk-go/clients"
"github.com/nacos-group/nacos-sdk-go/clients/naming_client"
"github.com/nacos-group/nacos-sdk-go/common/constant"
"github.com/nacos-group/nacos-sdk-go/vo"
"go.uber.org/zap"
"log"
)
const (
clusters = "GIN_FRAME"
groupName = "GIN_FRAME_GROUP"
)
type WarningConfig struct {
RoomId int
Url string
}
type NacosConfig struct {
Addr string
Port int
LogPath string
CachePath string
}
type nacosRF struct {
client naming_client.INamingClient
}
var NacosInstance *nacosRF
// InitNacos init Nacos
func InitNacos(config *NacosConfig) *nacosRF {
//return &nacosRF{}
d := &nacosRF{}
clientConfig := constant.ClientConfig{
TimeoutMs: 5000,
NotLoadCacheAtStart: true,
LogDir: config.LogPath,
CacheDir: config.CachePath,
LogLevel: "debug",
}
serverConfigs := []constant.ServerConfig{
{
IpAddr: config.Addr,
ContextPath: "/nacos",
Port: uint64(config.Port),
Scheme: "http",
},
}
var err error
d.client, err = clients.NewNamingClient(
vo.NacosClientParam{
ClientConfig: &clientConfig,
ServerConfigs: serverConfigs,
},
)
if err != nil {
log.Fatal("nacos失败了,err:%v", zap.Error(err))
}
NacosInstance = d
return d
}