@@ -93,7 +93,7 @@ func NewNamingClient(nc nacos_client.INacosClient) (NamingClient, error) {
93
93
return naming , nil
94
94
}
95
95
96
- //RegisterInstance register instance
96
+ // RegisterInstance register instance
97
97
func (sc * NamingClient ) RegisterInstance (param vo.RegisterInstanceParam ) (bool , error ) {
98
98
if param .ServiceName == "" {
99
99
return false , errors .New ("serviceName cannot be empty!" )
@@ -135,7 +135,7 @@ func (sc *NamingClient) RegisterInstance(param vo.RegisterInstanceParam) (bool,
135
135
136
136
}
137
137
138
- //DeregisterInstance deregister instance
138
+ // DeregisterInstance deregister instance
139
139
func (sc * NamingClient ) DeregisterInstance (param vo.DeregisterInstanceParam ) (bool , error ) {
140
140
if len (param .GroupName ) == 0 {
141
141
param .GroupName = constant .DEFAULT_GROUP
@@ -149,7 +149,7 @@ func (sc *NamingClient) DeregisterInstance(param vo.DeregisterInstanceParam) (bo
149
149
return true , nil
150
150
}
151
151
152
- //UpdateInstance update information for exist instance.
152
+ // UpdateInstance update information for exist instance.
153
153
func (sc * NamingClient ) UpdateInstance (param vo.UpdateInstanceParam ) (bool , error ) {
154
154
if len (param .GroupName ) == 0 {
155
155
param .GroupName = constant .DEFAULT_GROUP
@@ -183,7 +183,7 @@ func (sc *NamingClient) UpdateInstance(param vo.UpdateInstanceParam) (bool, erro
183
183
return true , nil
184
184
}
185
185
186
- //GetService get service info
186
+ // GetService get service info
187
187
func (sc * NamingClient ) GetService (param vo.GetServiceParam ) (model.Service , error ) {
188
188
if len (param .GroupName ) == 0 {
189
189
param .GroupName = constant .DEFAULT_GROUP
@@ -192,7 +192,7 @@ func (sc *NamingClient) GetService(param vo.GetServiceParam) (model.Service, err
192
192
return service , err
193
193
}
194
194
195
- //GetAllServicesInfo get all services info
195
+ // GetAllServicesInfo get all services info
196
196
func (sc * NamingClient ) GetAllServicesInfo (param vo.GetAllServiceInfoParam ) (model.ServiceList , error ) {
197
197
if len (param .GroupName ) == 0 {
198
198
param .GroupName = constant .DEFAULT_GROUP
@@ -214,7 +214,7 @@ func (sc *NamingClient) GetAllServicesInfo(param vo.GetAllServiceInfoParam) (mod
214
214
return services , nil
215
215
}
216
216
217
- //SelectAllInstances select all instances
217
+ // SelectAllInstances select all instances
218
218
func (sc * NamingClient ) SelectAllInstances (param vo.SelectAllInstancesParam ) ([]model.Instance , error ) {
219
219
if len (param .GroupName ) == 0 {
220
220
param .GroupName = constant .DEFAULT_GROUP
@@ -226,7 +226,7 @@ func (sc *NamingClient) SelectAllInstances(param vo.SelectAllInstancesParam) ([]
226
226
return service .Hosts , err
227
227
}
228
228
229
- //SelectInstances select instances
229
+ // SelectInstances select instances
230
230
func (sc * NamingClient ) SelectInstances (param vo.SelectInstancesParam ) ([]model.Instance , error ) {
231
231
if len (param .GroupName ) == 0 {
232
232
param .GroupName = constant .DEFAULT_GROUP
@@ -252,7 +252,7 @@ func (sc *NamingClient) selectInstances(service model.Service, healthy bool) ([]
252
252
return result , nil
253
253
}
254
254
255
- //SelectOneHealthyInstance select one healthy instance
255
+ // SelectOneHealthyInstance select one healthy instance
256
256
func (sc * NamingClient ) SelectOneHealthyInstance (param vo.SelectOneHealthInstanceParam ) (* model.Instance , error ) {
257
257
if len (param .GroupName ) == 0 {
258
258
param .GroupName = constant .DEFAULT_GROUP
@@ -284,28 +284,27 @@ func (sc *NamingClient) selectOneHealthyInstances(service model.Service) (*model
284
284
return nil , errors .New ("healthy instance list is empty!" )
285
285
}
286
286
287
- chooser := newChooser (result )
288
- instance := chooser .pick ()
287
+ instance := newChooser (result ).pick ()
289
288
return & instance , nil
290
289
}
291
290
292
- type instance []model.Instance
291
+ type instances []model.Instance
293
292
294
- func (a instance ) Len () int {
293
+ func (a instances ) Len () int {
295
294
return len (a )
296
295
}
297
296
298
- func (a instance ) Swap (i , j int ) {
297
+ func (a instances ) Swap (i , j int ) {
299
298
a [i ], a [j ] = a [j ], a [i ]
300
299
}
301
300
302
- func (a instance ) Less (i , j int ) bool {
301
+ func (a instances ) Less (i , j int ) bool {
303
302
return a [i ].Weight < a [j ].Weight
304
303
}
305
304
306
305
// NewChooser initializes a new Chooser for picking from the provided Choices.
307
- func newChooser (instances []model. Instance ) Chooser {
308
- sort .Sort (instance ( instances ) )
306
+ func newChooser (instances instances ) Chooser {
307
+ sort .Sort (instances )
309
308
totals := make ([]int , len (instances ))
310
309
runningTotal := 0
311
310
for i , c := range instances {
@@ -321,7 +320,7 @@ func (chs Chooser) pick() model.Instance {
321
320
return chs .data [i ]
322
321
}
323
322
324
- //Subscribe subscibe service
323
+ // Subscribe subscribe service
325
324
func (sc * NamingClient ) Subscribe (param * vo.SubscribeParam ) error {
326
325
if len (param .GroupName ) == 0 {
327
326
param .GroupName = constant .DEFAULT_GROUP
@@ -337,13 +336,13 @@ func (sc *NamingClient) Subscribe(param *vo.SubscribeParam) error {
337
336
if err != nil {
338
337
return err
339
338
}
340
- if ! sc .hostReactor .serviceProxy .clientConfig .NotLoadCacheAtStart {
339
+ if sc .hostReactor .serviceProxy .clientConfig .NotLoadCacheAtStart {
341
340
sc .subCallback .ServiceChanged (& svc )
342
341
}
343
342
return nil
344
343
}
345
344
346
- //Unsubscribe unsubscribe service
345
+ // Unsubscribe unsubscribe service
347
346
func (sc * NamingClient ) Unsubscribe (param * vo.SubscribeParam ) error {
348
347
sc .subCallback .RemoveCallbackFuncs (util .GetGroupName (param .ServiceName , param .GroupName ), strings .Join (param .Clusters , "," ), & param .SubscribeCallback )
349
348
return nil
0 commit comments