Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

upgrade nacos sdk #199

Merged
merged 1 commit into from
Aug 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions ext/datasource/nacos/nacos.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ type NacosDataSource struct {
isInitialized util.AtomicBool
group string
dataId string
closeChan chan struct{}
}

func NewNacosDataSource(client config_client.IConfigClient, group, dataId string, handlers ...datasource.PropertyHandler) (*NacosDataSource, error) {
Expand All @@ -32,11 +31,10 @@ func NewNacosDataSource(client config_client.IConfigClient, group, dataId string
return nil, errors.New(fmt.Sprintf("Invalid parameters, group: %s, dataId: %s", group, dataId))
}
var ds = &NacosDataSource{
Base: datasource.Base{},
client: client,
group: group,
dataId: dataId,
closeChan: make(chan struct{}, 1),
Base: datasource.Base{},
client: client,
group: group,
dataId: dataId,
}
for _, h := range handlers {
ds.AddPropertyHandler(h)
Expand Down Expand Up @@ -90,7 +88,6 @@ func (s *NacosDataSource) listen(client config_client.IConfigClient) (err error)
logger.Errorf("Fail to update data source, err: %+v", err)
}
},
ListenCloseChan: s.closeChan,
}
err = client.ListenConfig(listener)
if err != nil {
Expand All @@ -100,7 +97,13 @@ func (s *NacosDataSource) listen(client config_client.IConfigClient) (err error)
}

func (s *NacosDataSource) Close() error {
s.closeChan <- struct{}{}
err := s.client.CancelListenConfig(vo.ConfigParam{
DataId: s.dataId,
Group: s.group,
})
if err != nil {
return errors.Errorf("Failed to cancel listen to the nacos data source, err: %+v", err)
}
logger.Infof("The nacos datasource had been closed, group: %s, dataId: %s", s.group, s.dataId)
return nil
}
6 changes: 6 additions & 0 deletions ext/datasource/nacos/nacos_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ func (n *nacosClientMock) ListenConfig(params vo.ConfigParam) (err error) {
ret := n.Called(params)
return ret.Error(0)
}

func (n *nacosClientMock) CancelListenConfig(params vo.ConfigParam) (err error) {
ret := n.Called(params)
return ret.Error(0)
}

func (n *nacosClientMock) SearchConfig(param vo.SearchConfigParm) (*model.ConfigPage, error) {
ret := n.Called(param)
return ret.Get(0).(*model.ConfigPage), ret.Error(1)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ require (
github.com/google/uuid v1.1.1
github.com/hashicorp/consul/api v1.4.0
github.com/labstack/echo/v4 v4.1.15
github.com/nacos-group/nacos-sdk-go v0.4.0
github.com/nacos-group/nacos-sdk-go v1.0.0
github.com/pkg/errors v0.9.1
github.com/shirou/gopsutil v2.19.12+incompatible
github.com/stretchr/testify v1.5.1
Expand Down
7 changes: 4 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -338,8 +338,8 @@ github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3Rllmb
github.com/munnerz/goautoneg v0.0.0-20120707110453-a547fc61f48d/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ=
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
github.com/nacos-group/nacos-sdk-go v0.3.2/go.mod h1:4TdsN7eZnnVCDlOlBa61b0gsRnvNJI74m9+2+OKZkcw=
github.com/nacos-group/nacos-sdk-go v0.4.0 h1:DmnsYXFxK7MHUsmmFOug9w6HH0/WIeU+WFDvXc30t3I=
github.com/nacos-group/nacos-sdk-go v0.4.0/go.mod h1:MfkNtW4vNuRK7em17n3nbIA2lTfvr0klOmOFyL4/RdM=
github.com/nacos-group/nacos-sdk-go v1.0.0 h1:CufUF7DZca2ZzIrJtMMCDih1sA58BWCglArLMCZArUc=
github.com/nacos-group/nacos-sdk-go v1.0.0/go.mod h1:hlAPn3UdzlxIlSILAyOXKxjFSvDJ9oLzTJ9hLAK1KzA=
github.com/nicolai86/scaleway-sdk v1.10.2-0.20180628010248-798f60e20bb2/go.mod h1:TLb2Sg7HQcgGdloNxkrmtgDNR9uVYF3lfdFIN4Ro6Sk=
github.com/oklog/run v0.0.0-20180308005104-6934b124db28/go.mod h1:dlhp/R75TPv97u0XWUtDeV/lRKWPKSdTuV0TZvrmrQA=
github.com/onsi/ginkgo v0.0.0-20170829012221-11459a886d9c/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
Expand Down Expand Up @@ -444,7 +444,6 @@ github.com/ugorji/go/codec v1.1.7 h1:2SvQaVZ1ouYrrKKwoSk2pzd4A9evlKJb9oTL+OaLUSs
github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY=
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
github.com/valyala/fastrand v1.0.0/go.mod h1:HWqCzkrkg6QXT8V2EXWvXCoow7vLwOFN002oeRzjapQ=
github.com/valyala/fasttemplate v1.0.1/go.mod h1:UQGH1tvbgY+Nz5t2n7tXsz52dQxojPUpymEIMZ47gx8=
github.com/valyala/fasttemplate v1.1.0 h1:RZqt0yGBsps8NGvLSGW804QQqCUYYLsaOjTVHy1Ocw4=
github.com/valyala/fasttemplate v1.1.0/go.mod h1:UQGH1tvbgY+Nz5t2n7tXsz52dQxojPUpymEIMZ47gx8=
Expand All @@ -468,6 +467,8 @@ go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee h1:0mgffUl7nfd+FpvXMVz4IDEa
go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee/go.mod h1:vJERXedbb3MVM5f9Ejo0C68/HhF8uaILCdgjnY+goOA=
go.uber.org/zap v1.10.0 h1:ORx85nbTijNz8ljznvCMR1ZBIPKFn3jQrag10X2AsuM=
go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q=
go.uber.org/zap v1.15.0 h1:ZZCA22JRF2gQE5FoNmhmrf7jeJJ2uhqDUNRYKm8dvmM=
go.uber.org/zap v1.15.0/go.mod h1:Mb2vm2krFEG5DV0W9qcHBYFtp/Wku1cvYaqPsS/WYfc=
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20181029021203-45a5f77698d3/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
Expand Down