This repository has been archived by the owner on Oct 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathapi.go
49 lines (44 loc) · 1.67 KB
/
api.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
49
package grpc_resolver_nacos
import "github.com/nacos-group/nacos-sdk-go/v2/vo"
func GetService(serviceName string, clusters []string, groupName string, nacosClient NacosClient) (NacosService, error) {
service, err := nacosClient.GetService(vo.GetServiceParam{
ServiceName: serviceName,
Clusters: clusters,
GroupName: groupName, // 默认值DEFAULT_GROUP
})
return service, err
}
func GetOneHealthyInstance(serviceName string, clusters []string, groupName string, nacosClient NacosClient) (*NacosInstance, error) {
instance, err := nacosClient.SelectOneHealthyInstance(vo.SelectOneHealthInstanceParam{
ServiceName: serviceName,
Clusters: clusters,
GroupName: groupName, // 默认值DEFAULT_GROUP
})
return instance, err
}
func GetHealthyInstances(serviceName string, clusters []string, groupName string, nacosClient NacosClient) ([]NacosInstance, error) {
instances, err := nacosClient.SelectInstances(vo.SelectInstancesParam{
ServiceName: serviceName,
Clusters: clusters,
GroupName: groupName, // 默认值DEFAULT_GROUP
HealthyOnly: true,
})
return instances, err
}
func RegisterInstance(ip string, port uint64, serviceName string, weight float64, enable bool, healthy bool,
metadata map[string]string, clusterName string, groupName string, ephemeral bool, nacosClient NacosClient) (bool, error) {
param := vo.RegisterInstanceParam{
Ip: ip,
Port: port,
ServiceName: serviceName,
Weight: weight,
Enable: enable,
Healthy: healthy,
Metadata: metadata,
ClusterName: clusterName,
GroupName: groupName,
Ephemeral: ephemeral,
}
success, err := nacosClient.RegisterInstance(param)
return success, err
}