@@ -87,8 +87,10 @@ func (asl *applicationServiceListener) WatchAndHandle() {
87
87
return
88
88
}
89
89
if failTimes > MaxFailTimes {
90
- logger .Errorf ("Error happens on (path{%s}) exceed max fail times: %v,so exit listen" ,
91
- asl .servicePath , MaxFailTimes )
90
+ logger .Errorf (
91
+ "Error happens on (path{%s}) exceed max fail times: %v,so exit listen" ,
92
+ asl .servicePath , MaxFailTimes ,
93
+ )
92
94
return
93
95
}
94
96
delayTimer .Reset (ConnDelay * time .Duration (failTimes ))
@@ -113,8 +115,10 @@ func (asl *applicationServiceListener) waitEventAndHandlePeriod(children []strin
113
115
case <- ticker .C :
114
116
asl .handleEvent (children )
115
117
case zkEvent := <- e :
116
- logger .Warnf ("get a zookeeper e{type:%s, server:%s, path:%s, state:%d-%s, err:%s}" ,
117
- zkEvent .Type .String (), zkEvent .Server , zkEvent .Path , zkEvent .State , zookeeper .StateToString (zkEvent .State ), zkEvent .Err )
118
+ logger .Warnf (
119
+ "get a zookeeper e{type:%s, server:%s, path:%s, state:%d-%s, err:%s}" ,
120
+ zkEvent .Type .String (), zkEvent .Server , zkEvent .Path , zkEvent .State , zookeeper .StateToString (zkEvent .State ), zkEvent .Err ,
121
+ )
118
122
if zkEvent .Type != zk .EventNodeChildrenChanged {
119
123
return true
120
124
}
@@ -169,7 +173,7 @@ func (asl *applicationServiceListener) handleEvent(children []string) {
169
173
MapTo : "opt.types" ,
170
174
},
171
175
}
172
- if methods != nil && len (methods ) != 0 {
176
+ if len (methods ) != 0 {
173
177
for i := range methods {
174
178
api := registry .CreateAPIConfig (apiPattern , location , bkConfig , methods [i ], mappingParams )
175
179
if err := asl .adapterListener .OnAddAPI (api ); err != nil {
@@ -211,7 +215,7 @@ func (asl *applicationServiceListener) getUrls(path string) []*dubboCommon.URL {
211
215
return nil
212
216
}
213
217
instance .SetServiceMetadata (metadataInfo )
214
- urls := make ([]* dubboCommon.URL , 0 )
218
+ urls := make ([]* dubboCommon.URL , 0 , len ( metadataInfo . Services ) )
215
219
for _ , service := range metadataInfo .Services {
216
220
urls = append (urls , instance .ToURLs (service )... )
217
221
}
@@ -247,8 +251,6 @@ func toZookeeperInstance(cris *curator_discovery.ServiceInstance) dr.ServiceInst
247
251
248
252
// getMethods return the methods of a service
249
253
func (asl * applicationServiceListener ) getMethods (in string ) ([]string , error ) {
250
- methods := []string {}
251
-
252
254
path := strings .Join ([]string {methodsRootPath , in }, constant .PathSlash )
253
255
data , err := asl .client .GetContent (path )
254
256
if err != nil {
@@ -261,8 +263,9 @@ func (asl *applicationServiceListener) getMethods(in string) ([]string, error) {
261
263
return nil , err
262
264
}
263
265
264
- for _ , m := range sd .Methods {
265
- methods = append (methods , m .Name )
266
+ methods := make ([]string , len (sd .Methods ))
267
+ for i := range sd .Methods {
268
+ methods [i ] = sd .Methods [i ].Name
266
269
}
267
270
return methods , nil
268
271
}
0 commit comments