-
Notifications
You must be signed in to change notification settings - Fork 6
/
client.go
48 lines (40 loc) · 1002 Bytes
/
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
package nacos
import (
"sync"
"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"
logf "sigs.k8s.io/controller-runtime/pkg/log"
)
var (
nClient naming_client.INamingClient
lock sync.Mutex
)
var log = logf.Log.WithName("nacos")
// NewClient ...
func NewClient() (naming_client.INamingClient, error) {
var err error
lock.Lock()
defer lock.Unlock()
if nClient == nil {
log.Info("Starting create a new nacos client.")
nc, e := clients.CreateNamingClient(map[string]interface{}{
"serverConfigs": []constant.ServerConfig{
{
IpAddr: "10.248.224.144",
Port: 8848,
ContextPath: "/nacos",
},
},
"clientConfig": constant.ClientConfig{
TimeoutMs: 10 * 1000,
BeatInterval: 5 * 1000,
ListenInterval: 30 * 1000,
NotLoadCacheAtStart: true,
},
})
nClient = nc
err = e
}
return nClient, err
}