Skip to content

Commit 415dce2

Browse files
author
tietang
committed
update nacos go sdk to 1.0.1
1 parent 982252f commit 415dce2

7 files changed

+34
-32
lines changed

.gitignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,6 @@ etcd/temp/
2222
vendor/
2323
**/temp/
2424
_vendor-20180703123224/
25-
vendor/**
25+
vendor/**
26+
/nacos/
27+
/go.sum

go.mod

+1-4
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ require (
5252
github.com/hashicorp/serf v0.9.2 // indirect
5353
github.com/mitchellh/go-testing-interface v1.14.1 // indirect
5454
github.com/mitchellh/mapstructure v1.3.2 // indirect
55-
github.com/nacos-group/nacos-sdk-go v0.3.2
55+
github.com/nacos-group/nacos-sdk-go v1.0.1
5656
github.com/prometheus/common v0.10.0
5757
github.com/samuel/go-zookeeper v0.0.0-20180130194729-c4fab1ac1bec
5858
github.com/satori/go.uuid v1.2.1-0.20181028125025-b2ce2384e17b
@@ -65,9 +65,6 @@ require (
6565
github.com/valyala/fasttemplate v1.1.0
6666
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2 // indirect
6767
go.etcd.io/bbolt v1.3.2 // indirect
68-
go.uber.org/atomic v1.4.0 // indirect
69-
go.uber.org/multierr v1.1.0 // indirect
70-
go.uber.org/zap v1.10.0 // indirect
7168
golang.org/x/crypto v0.0.0-20191106202628-ed6320f186d4 // indirect
7269
golang.org/x/sys v0.0.0-20200602225109-6fdc65e7d980 // indirect
7370
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4 // indirect

nacos/nacos_client_props_source.go

+21-20
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ type NacosClientPropsConfigSource struct {
3333
//
3434
name string
3535
lastCt uint32
36-
ClientConfig constant.ClientConfig
36+
ClientConfig *constant.ClientConfig
3737
ServerConfigs []constant.ServerConfig
3838
Client config_client.IConfigClient
3939
}
@@ -45,15 +45,16 @@ func NewNacosClientPropsConfigSource(address, group, dataId, tenant string) *Nac
4545
s.DataId = dataId
4646
s.Group = group
4747
s.Tenant = tenant
48-
s.ClientConfig = constant.ClientConfig{
49-
TimeoutMs: 10 * 1000, //http请求超时时间,单位毫秒
50-
ListenInterval: 30 * 1000, //监听间隔时间,单位毫秒(仅在ConfigClient中有效)
51-
BeatInterval: 5 * 1000, //心跳间隔时间,单位毫秒(仅在ServiceClient中有效)
52-
CacheDir: "./data/nacos/cache", //缓存目录
53-
LogDir: "./data/nacos/log", //日志目录
54-
UpdateThreadNum: 20, //更新服务的线程数
55-
NotLoadCacheAtStart: true, //在启动时不读取本地缓存数据,true--不读取,false--读取
56-
UpdateCacheWhenEmpty: true, //当服务列表为空时是否更新本地缓存,true--更新,false--不更新
48+
s.ClientConfig = &constant.ClientConfig{
49+
TimeoutMs: 10 * 1000, //请求Nacos服务端的超时时间,默认是10000ms
50+
BeatInterval: 5 * 1000, //心跳间隔时间,单位毫秒(仅在ServiceClient中有效)
51+
CacheDir: "./nacos/cache", //缓存目录
52+
LogDir: "./nacos/log", //日志目录
53+
UpdateThreadNum: 20, //更新服务的线程数
54+
NotLoadCacheAtStart: true, //在启动时不读取本地缓存数据,true--不读取,false--读取
55+
UpdateCacheWhenEmpty: false, //当服务列表为空时是否更新本地缓存,true--更新,false--不更新,当service返回的实例列表为空时,不更新缓存,用于推空保护
56+
RotateTime: "1h", // 日志轮转周期,比如:30m, 1h, 24h, 默认是24h
57+
MaxAge: 3, // 日志最大文件数,默认3
5758
}
5859
if len(tenant) > 0 {
5960
s.ClientConfig.NamespaceId = tenant
@@ -85,7 +86,7 @@ func NewNacosClientPropsConfigSource(address, group, dataId, tenant string) *Nac
8586
var err error
8687
s.Client, err = clients.CreateConfigClient(map[string]interface{}{
8788
constant.KEY_SERVER_CONFIGS: s.ServerConfigs,
88-
constant.KEY_CLIENT_CONFIG: s.ClientConfig,
89+
constant.KEY_CLIENT_CONFIG: *s.ClientConfig,
8990
})
9091
if err != nil {
9192
log.Panic("error create ConfigClient: ", err)
@@ -116,11 +117,11 @@ func (s *NacosClientPropsConfigSource) watchContext() {
116117
DataId: "dataId",
117118
Group: "group",
118119
}
119-
if len(s.AppName) > 0 {
120-
cp.AppName = s.AppName
121-
}
120+
//if len(s.AppName) > 0 {
121+
// cp.AppName = s.AppName
122+
//}
122123
cp.OnChange = func(namespace, group, dataId, data string) {
123-
s.parseAndregisterProps([]byte(data))
124+
s.parseAndRegisterProps([]byte(data))
124125
log.Info("changed config:", namespace, group, dataId)
125126
}
126127
s.Client.ListenConfig(cp)
@@ -137,11 +138,11 @@ func (s *NacosClientPropsConfigSource) findProperties() {
137138
log.Error(err)
138139
return
139140
}
140-
s.parseAndregisterProps(data)
141+
s.parseAndRegisterProps(data)
141142

142143
}
143144

144-
func (s *NacosClientPropsConfigSource) parseAndregisterProps(data []byte) {
145+
func (s *NacosClientPropsConfigSource) parseAndRegisterProps(data []byte) {
145146
sep := s.LineSeparator
146147
if sep == "" {
147148
sep = NACOS_LINE_SEPARATOR
@@ -179,9 +180,9 @@ func (h *NacosClientPropsConfigSource) get() (body []byte, err error) {
179180
DataId: "dataId",
180181
Group: "group",
181182
}
182-
if len(h.AppName) > 0 {
183-
cp.AppName = h.AppName
184-
}
183+
//if len(h.AppName) > 0 {
184+
// cp.AppName = h.AppName
185+
//}
185186
content, err := h.Client.GetConfig(cp)
186187
if err != nil {
187188
log.Error(err)

nacos/nacos_client_props_source_test.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,11 @@ import (
77
"time"
88
)
99

10+
//var address = "console.nacos.io"
11+
var address = "172.16.1.248:8848"
12+
1013
func TestNacosClientIniConfigSource2(t *testing.T) {
11-
address := "console.nacos.io"
14+
1215
//http://console.nacos.io/nacos/v1/cs/configs?
1316
// show=all&dataId=xxx123&group=DEFAULT_GROUP&tenant=&namespaceId=
1417
dataId := "xxx123"
@@ -22,7 +25,7 @@ func TestNacosClientIniConfigSource(t *testing.T) {
2225
//address := "172.16.1.248:8848"
2326
//http://console.nacos.io/nacos/v1/cs/configs?show=all&dataId=q123&group=DEFAULT_GROUP&tenant=&namespaceId=
2427
//http://console.nacos.io/nacos/v1/cs/configs
25-
address := "console.nacos.io"
28+
//address := "console.nacos.io"
2629

2730
size := 10
2831
inilen := 3

nacos/nacos_client_source.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,9 @@ func (h *NacosClientConfigSource) get() (cr *ConfigRes, err error) {
101101
DataId: "dataId",
102102
Group: "group",
103103
}
104-
if len(h.AppName) > 0 {
105-
cp.AppName = h.AppName
106-
}
104+
//if len(h.AppName) > 0 {
105+
// cp.AppName = h.AppName
106+
//}
107107
content, err := h.Client.GetConfig(cp)
108108
if err != nil {
109109
log.Error(err)

nacos/nacos_data_test.go

-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ func update(group, dataId, tenant string, size, len int) map[string]string {
3636
DataId: dataId,
3737
Group: group,
3838
Content: "",
39-
Tag: "",
4039
}
4140
b, e := c.PublishConfig(vo)
4241
fmt.Println(b, e)

nacos/nacos_props_source.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"fmt"
1010
"github.com/nacos-group/nacos-sdk-go/common/constant"
1111
"github.com/nacos-group/nacos-sdk-go/common/nacos_error"
12-
"github.com/nacos-group/nacos-sdk-go/common/util"
12+
"github.com/nacos-group/nacos-sdk-go/util"
1313
uuid "github.com/satori/go.uuid"
1414
log "github.com/sirupsen/logrus"
1515
"github.com/tietang/props/v3/kvs"

0 commit comments

Comments
 (0)