forked from polarismesh/polaris-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
api.go
152 lines (128 loc) · 5.48 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
/**
* Tencent is pleased to support the open source community by making polaris-go available.
*
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
*
* Licensed under the BSD 3-Clause License (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://opensource.org/licenses/BSD-3-Clause
*
* Unless required by applicable law or agreed to in writing, software distributed
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
// Package polaris api defines the interfaces for the external APIs.
package polaris
import (
"github.com/polarismesh/polaris-go/api"
"github.com/polarismesh/polaris-go/pkg/model"
)
// GetOneInstanceRequest is the request struct for GetOneInstance.
type GetOneInstanceRequest api.GetOneInstanceRequest
// GetInstancesRequest is the request struct for GetInstances.
type GetInstancesRequest api.GetInstancesRequest
// GetAllInstancesRequest is the request struct for GetAllInstances.
type GetAllInstancesRequest api.GetAllInstancesRequest
// GetServiceRuleRequest is the request struct for GetServiceRule.
type GetServiceRuleRequest api.GetServiceRuleRequest
// ServiceCallResult is the response struct for ServiceCall.
type ServiceCallResult api.ServiceCallResult
// WatchServiceRequest is the request struct for WatchService.
type WatchServiceRequest api.WatchServiceRequest
// GetServicesRequest is the request struct for GetServices.
type GetServicesRequest api.GetServicesRequest
// InitCalleeServiceRequest is the request struct for InitCalleeService.
type InitCalleeServiceRequest api.InitCalleeServiceRequest
// ConsumerAPI 主调端API方法.
type ConsumerAPI interface {
api.SDKOwner
// GetOneInstance 同步获取单个服务
GetOneInstance(req *GetOneInstanceRequest) (*model.OneInstanceResponse, error)
// GetInstances 同步获取可用的服务列表
GetInstances(req *GetInstancesRequest) (*model.InstancesResponse, error)
// GetAllInstances 同步获取完整的服务列表
GetAllInstances(req *GetAllInstancesRequest) (*model.InstancesResponse, error)
// GetRouteRule 同步获取服务路由规则
GetRouteRule(req *GetServiceRuleRequest) (*model.ServiceRuleResponse, error)
// UpdateServiceCallResult 上报服务调用结果
UpdateServiceCallResult(req *ServiceCallResult) error
// WatchService 订阅服务消息
WatchService(req *WatchServiceRequest) (*model.WatchServiceResponse, error)
// GetServices 根据业务同步获取批量服务
GetServices(req *GetServicesRequest) (*model.ServicesResponse, error)
// InitCalleeService 初始化服务运行中需要的被调服务
InitCalleeService(req *InitCalleeServiceRequest) error
// Destroy 销毁API,销毁后无法再进行调用
Destroy()
}
// InstanceRegisterRequest 实例注册请求.
type InstanceRegisterRequest api.InstanceRegisterRequest
// InstanceDeRegisterRequest 实例注销请求.
type InstanceDeRegisterRequest api.InstanceDeRegisterRequest
// InstanceHeartbeatRequest 实例心跳请求.
type InstanceHeartbeatRequest api.InstanceHeartbeatRequest
// ProviderAPI CL5服务端API的主接口.
type ProviderAPI interface {
api.SDKOwner
// RegisterInstance
// minimum supported version of polaris-server is v1.10.0
RegisterInstance(instance *InstanceRegisterRequest) (*model.InstanceRegisterResponse, error)
// Deprecated: Use RegisterInstance instead.
// Register
// 同步注册服务,服务注册成功后会填充instance中的InstanceID字段
// 用户可保持该instance对象用于反注册和心跳上报
Register(instance *InstanceRegisterRequest) (*model.InstanceRegisterResponse, error)
// Deregister
// 同步反注册服务
Deregister(instance *InstanceDeRegisterRequest) error
// Deprecated: Use RegisterInstance instead.
// Heartbeat
// 心跳上报
Heartbeat(instance *InstanceHeartbeatRequest) error
// Destroy
// 销毁API,销毁后无法再进行调用
Destroy()
}
// QuotaRequest rate limiter.
type QuotaRequest api.QuotaRequest
// QuotaFuture rate limiter.
type QuotaFuture api.QuotaFuture
// LimitAPI 限流相关的API相关接口.
type LimitAPI interface {
api.SDKOwner
// GetQuota the interface obtains only one quota at a time
GetQuota(request QuotaRequest) (QuotaFuture, error)
// Destroy the api is destroyed and cannot be called again
Destroy()
}
// NewQuotaRequest example create a quota query request.
func NewQuotaRequest() QuotaRequest {
return &model.QuotaRequestImpl{}
}
// ConfigFile config
type ConfigFile model.ConfigFile
// ConfigAPI api for configuration files.
type ConfigAPI interface {
api.SDKOwner
// GetConfigFile obtaining the configuration file
GetConfigFile(namespace, fileGroup, fileName string) (ConfigFile, error)
}
// RouterAPI routing api methods
type RouterAPI interface {
api.SDKOwner
// ProcessRouters process routers to filter instances
ProcessRouters(*ProcessRoutersRequest) (*model.InstancesResponse, error)
// ProcessLoadBalance process load balancer to get the target instances
ProcessLoadBalance(*ProcessLoadBalanceRequest) (*model.OneInstanceResponse, error)
}
// ProcessRoutersRequest process routers to filter instances
type ProcessRoutersRequest struct {
model.ProcessRoutersRequest
}
// ProcessLoadBalanceRequest process load balancer to get the target instances
type ProcessLoadBalanceRequest struct {
model.ProcessLoadBalanceRequest
}