Documentation ¶
Overview ¶
Package api is the core API of polaris-go, which provides the basic functions of service discovery and.
Index ¶
- Constants
- Variables
- func CheckAvailable(owner SDKOwner) error
- func ConfigBaseLogger(logDir string, logLevel int) error
- func ConfigCacheLogger(logDir string, logLevel int) error
- func ConfigDetectLogger(logDir string, logLevel int) error
- func ConfigLoggers(logDir string, logLevel int) error
- func ConfigNetworkLogger(logDir string, logLevel int) error
- func ConfigStatLogger(logDir string, logLevel int) error
- func ConfigStatReportLogger(logDir string, logLevel int) error
- func NewConfiguration() config.Configuration
- func SetBaseLogger(logger Logger)
- func SetCacheLogger(logger Logger)
- func SetDetectLogger(logger Logger)
- func SetLoggersDir(logDir string) error
- func SetLoggersLevel(loglevel int) error
- func SetStatLogger(logger Logger)
- func SetStatReportLogger(logger Logger)
- type ConfigFileAPI
- type ConfigGroupAPI
- type ConsumerAPI
- type GetAllInstancesRequest
- type GetInstancesRequest
- type GetOneInstanceRequest
- type GetServiceRuleRequest
- type GetServicesRequest
- type InitCalleeServiceRequest
- type InstanceDeRegisterRequest
- type InstanceHeartbeatRequest
- type InstanceRegisterRequest
- type InstanceRequest
- type LimitAPI
- type Logger
- type ProviderAPI
- type QuotaFuture
- type QuotaRequest
- type SDKContext
- type SDKOwner
- type ServiceCallResult
- type WatchAllInstancesRequest
- type WatchAllServicesRequest
- type WatchServiceRequest
Constants ¶
const ( // LBPolicyWeightedRandom 权重随机负载均衡策略 LBPolicyWeightedRandom = config.DefaultLoadBalancerWR // LBPolicyRingHash 权重一致性hash负载均衡策略 LBPolicyRingHash = config.DefaultLoadBalancerRingHash // LBPolicyMaglev Maglev算法的一致性hash负载均衡策略 LBPolicyMaglev = config.DefaultLoadBalancerMaglev // LBPolicyL5CST L5一致性Hash兼容算法,保证和L5产生相同的结果 LBPolicyL5CST = config.DefaultLoadBalancerL5CST )
const ( // RetSuccess the call is successful RetSuccess = model.RetSuccess // RetFail call fails RetFail = model.RetFail )
const ( // WatchModeLongPull watch model by long pulling, the invocation would be hang on until revision updated or timeout WatchModeLongPull = model.WatchModeLongPull // WatchModeNotify watch model by notify to listener WatchModeNotify = model.WatchModeNotify )
const ( // QuotaResultOk 限流状态值 QuotaResultOk = model.QuotaResultOk // QuotaResultLimited 限流结果 QuotaResultLimited = model.QuotaResultLimited )
const ( // TraceLog 跟踪级别 TraceLog = log.TraceLog // DebugLog 调试级别 DebugLog = log.DebugLog // InfoLog 一般日志级别 InfoLog = log.InfoLog // WarnLog 警告日志级别 WarnLog = log.WarnLog // ErrorLog 错误日志级别 ErrorLog = log.ErrorLog // FatalLog 致命级别 FatalLog = log.FatalLog // NoneLog 当要禁止日志的时候,可以设置此级别 NoneLog = log.NoneLog )
日志级别
const ( // DefaultBaseLogLevel 默认基本日志级别 DefaultBaseLogLevel = log.DefaultBaseLogLevel // DefaultStatLogLevel 默认统计日志级别 DefaultStatLogLevel = log.DefaultStatLogLevel // DefaultDetectLogLevel 默认探测日志级别 DefaultDetectLogLevel = log.DefaultDetectLogLevel // DefaultStatReportLogLevel 默认统计上报日志级别 DefaultStatReportLogLevel = log.DefaultStatReportLogLevel // DefaultNetworkLogLevel 默认网络交互日志级别 DefaultNetworkLogLevel = log.DefaultNetworkLogLevel // DefaultCacheLogLevel 默认缓存日志级别 DefaultCacheLogLevel = log.DefaultCacheLogLevel )
const ( // EventInstance . EventInstance = model.EventInstance )
Variables ¶
var ( // NewConfigFileAPIBySDKContext 通过 SDKContext 创建 ConfigFileAPI NewConfigFileAPIBySDKContext = newConfigFileAPIBySDKContext // NewConfigFileAPI 通过 polaris.yaml 创建 ConfigFileAPI NewConfigFileAPI = newConfigFileAPI // NewConfigFileAPIByConfig 通过 Configuration 创建 ConfigFileAPI NewConfigFileAPIByConfig = newConfigFileAPIByConfig // NewConfigFileAPIByFile 通过配置文件创建 ConfigFileAPI NewConfigFileAPIByFile = newConfigFileAPIByFile // NewConfigGroupAPIBySDKContext 通过 SDKContext 创建 ConfigGroupAPI NewConfigGroupAPIBySDKContext = newConfigGroupAPIBySDKContext // NewConfigGroupAPI 通过 polaris.yaml 创建 ConfigGroupAPI NewConfigGroupAPI = newConfigGroupAPI // NewConfigGroupAPIByConfig 通过 Configuration 创建 ConfigGroupAPI NewConfigGroupAPIByConfig = newConfigGroupAPIByConfig // NewConfigGroupAPIByFile 通过配置文件创建 ConfigGroupAPI NewConfigGroupAPIByFile = newConfigGroupAPIByFile )
var ( // NewConsumerAPI 通过以默认域名为埋点server的默认配置创建ConsumerAPI NewConsumerAPI = newConsumerAPI // NewConsumerAPIByFile 通过配置文件创建SDK ConsumerAPI对象 NewConsumerAPIByFile = newConsumerAPIByFile // NewConsumerAPIByConfig 通过配置对象创建SDK ConsumerAPI对象 NewConsumerAPIByConfig = newConsumerAPIByConfig // NewConsumerAPIByContext 通过上下文创建SDK ConsumerAPI对象 NewConsumerAPIByContext = newConsumerAPIByContext // NewConsumerAPIByDefaultConfigFile 从系统默认配置文件中创建ConsumerAPI NewConsumerAPIByDefaultConfigFile = newConsumerAPIByDefaultConfigFile // NewServiceCallResult 创建上报对象 NewServiceCallResult = newServiceCallResult // NewConsumerAPIByAddress 通过address创建ConsumerAPI对象 NewConsumerAPIByAddress = newConsumerAPIByAddress )
var ( // NewLimitAPI 通过以默认域名为埋点server的默认配置创建LimitAPI NewLimitAPI = newLimitAPI // NewLimitAPIByConfig 通过配置对象创建LimitAPI NewLimitAPIByConfig = newLimitAPIByConfig // NewLimitAPIByContext 通过sdkContext创建LimitAPI NewLimitAPIByContext = newLimitAPIByContext // NewLimitAPIByFile 通过配置文件创建SDK LimitAPI对象 NewLimitAPIByFile = newLimitAPIByFile // NewLimitAPIByAddress 通过address创建LimitAPI NewLimitAPIByAddress = newLimitAPIByAddress )
var ( // NewProviderAPI 通过以默认域名为埋点server的默认配置创建ProviderAPI NewProviderAPI = newProviderAPI // NewProviderAPIByFile 通过配置文件创建SDK ProviderAPI对象 NewProviderAPIByFile = newProviderAPIByFile // NewProviderAPIByConfig 通过配置对象创建SDK ProviderAPI对象 NewProviderAPIByConfig = newProviderAPIByConfig // NewProviderAPIByContext 通过上下文创建SDK ProviderAPI对象 NewProviderAPIByContext = newProviderAPIByContext // NewProviderAPIByDefaultConfigFile 通过系统默认配置文件创建ProviderAPI NewProviderAPIByDefaultConfigFile = newProviderAPIByDefaultConfigFile // NewProviderAPIByAddress 通过address创建ProviderAPI对象 NewProviderAPIByAddress = newProviderAPIByAddress )
Functions ¶
func CheckAvailable ¶ added in v1.2.0
CheckAvailable 判断API是否可用
func ConfigBaseLogger ¶
ConfigBaseLogger 配置基础日志对象
func ConfigCacheLogger ¶ added in v1.4.0
ConfigCacheLogger 配置缓存更新日志对象
func ConfigDetectLogger ¶
ConfigDetectLogger 配置探测日志对象
func ConfigNetworkLogger ¶
ConfigNetworkLogger 配置网络交互日志对象
func ConfigStatLogger ¶
ConfigStatLogger 配置统计日志对象
func ConfigStatReportLogger ¶
ConfigStatReportLogger 配置统计上报日志对象
func SetLoggersDir ¶
SetLoggersDir 设置日志的目录,会创建新的具有默认打印级别的logger
Types ¶
type ConfigFileAPI ¶ added in v1.1.0
type ConfigFileAPI interface { SDKOwner // GetConfigFile 获取配置文件 GetConfigFile(namespace, fileGroup, fileName string) (model.ConfigFile, error) // CreateConfigFile 创建配置文件 CreateConfigFile(namespace, fileGroup, fileName, content string) error // UpdateConfigFile 更新配置文件 UpdateConfigFile(namespace, fileGroup, fileName, content string) error // PublishConfigFile 发布配置文件 PublishConfigFile(namespace, fileGroup, fileName string) error }
ConfigFileAPI 配置文件的 API
type ConfigGroupAPI ¶ added in v1.5.6
type ConfigGroupAPI interface { SDKOwner // GetConfigGroup 获取配置分组 GetConfigGroup(namespace, group string) (model.ConfigFileGroup, error) }
type ConsumerAPI ¶
type ConsumerAPI interface { 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 // Destroy 销毁API,销毁后无法再进行调用 Destroy() // Deprecated: please use WatchAllInstances instead // WatchService 订阅服务消息 WatchService(req *WatchServiceRequest) (*model.WatchServiceResponse, error) // GetServices 根据业务同步获取批量服务 GetServices(req *GetServicesRequest) (*model.ServicesResponse, error) // InitCalleeService 初始化服务运行中需要的被调服务 InitCalleeService(req *InitCalleeServiceRequest) error // WatchAllInstances 监听服务实例变更事件 WatchAllInstances(req *WatchAllInstancesRequest) (*model.WatchAllInstancesResponse, error) // WatchAllServices 监听服务列表变更事件 WatchAllServices(req *WatchAllServicesRequest) (*model.WatchAllServicesResponse, error) }
ConsumerAPI 主调端API方法
type GetAllInstancesRequest ¶
type GetAllInstancesRequest struct {
model.GetAllInstancesRequest
}
GetAllInstancesRequest 获取服务下所有实例的请求对象
type GetInstancesRequest ¶
type GetInstancesRequest struct {
model.GetInstancesRequest
}
GetInstancesRequest 获取多个服务的请求对象
type GetOneInstanceRequest ¶
type GetOneInstanceRequest struct {
model.GetOneInstanceRequest
}
GetOneInstanceRequest 获取单个服务的请求对象
type GetServiceRuleRequest ¶
type GetServiceRuleRequest struct {
model.GetServiceRuleRequest
}
GetServiceRuleRequest 获取服务规则请求
type GetServicesRequest ¶
type GetServicesRequest struct {
model.GetServicesRequest
}
GetServicesRequest 获取批量服务请求
type InitCalleeServiceRequest ¶
type InitCalleeServiceRequest struct {
model.InitCalleeServiceRequest
}
InitCalleeServiceRequest .
type InstanceDeRegisterRequest ¶
type InstanceDeRegisterRequest struct {
model.InstanceDeRegisterRequest
}
InstanceDeRegisterRequest 反注册服务请求
type InstanceHeartbeatRequest ¶
type InstanceHeartbeatRequest struct {
model.InstanceHeartbeatRequest
}
InstanceHeartbeatRequest 心跳上报请求
type InstanceRegisterRequest ¶
type InstanceRegisterRequest struct {
model.InstanceRegisterRequest
}
InstanceRegisterRequest 注册服务请求
type InstanceRequest ¶
type InstanceRequest struct { // 服务标识 model.ServiceKey // InstanceID 实例ID InstanceID string IP string Port uint16 }
InstanceRequest 实例请求
type LimitAPI ¶
type LimitAPI interface { SDKOwner // GetQuota 获取限流配额,一次接口只获取一个配额 GetQuota(request QuotaRequest) (QuotaFuture, error) // Destroy 销毁API,销毁后无法再进行调用 Destroy() }
LimitAPI 限流相关的API相关接口
type ProviderAPI ¶
type ProviderAPI interface { SDKOwner // RegisterInstance // minimum supported version of polaris-server is v1.10.0 RegisterInstance(instance *InstanceRegisterRequest) (*model.InstanceRegisterResponse, error) // Register // 同步注册服务,服务注册成功后会填充instance中的InstanceID字段 // 用户可保持该instance对象用于反注册和心跳上报 // Deprecated: Use RegisterInstance instead. Register(instance *InstanceRegisterRequest) (*model.InstanceRegisterResponse, error) // Deregister synchronize the anti registration service Deregister(instance *InstanceDeRegisterRequest) error // Heartbeat the heartbeat report // Deprecated: Use RegisterInstance instead. Heartbeat(instance *InstanceHeartbeatRequest) error // Destroy the api is destroyed and cannot be called again Destroy() }
ProviderAPI CL5服务端API的主接口
type QuotaFuture ¶
type QuotaFuture interface { // Done 标识分配是否结束 Done() <-chan struct{} // Get 等待一段时间后,获取分配结果,用于匀速排队 Get() *model.QuotaResponse // GetImmediately 立刻获取分配结果,不等待 GetImmediately() *model.QuotaResponse // Release 释放资源,仅用于并发数限流的场景 Release() }
QuotaFuture 实时/延时分配future
type QuotaRequest ¶
type QuotaRequest interface { // SetNamespace 设置命名空间 SetNamespace(string) // SetService 设置服务名 SetService(string) // SetLabels 设置业务标签信息 // Deprecated: please use AddArgument instead SetLabels(map[string]string) // SetMethod set method SetMethod(method string) // AddArgument add the match argument AddArgument(argument model.Argument) // SetToken set token to acquire SetToken(uint32) // SetTimeout 设置单次请求超时时间 SetTimeout(timeout time.Duration) // SetRetryCount 设置最大重试次数 SetRetryCount(retryCount int) }
QuotaRequest 配额查询请求
type SDKContext ¶
type SDKContext interface { // Destroy // @brief 销毁SDK上下文 Destroy() // IsDestroyed // @brief SDK上下文是否已经销毁 IsDestroyed() bool // GetConfig // @brief 获取全局配置信息 GetConfig() config.Configuration // GetPlugins // @brief 获取插件列表 GetPlugins() plugin.Manager // GetEngine // @brief 获取执行引擎 GetEngine() model.Engine // GetValueContext // @brief 获取值上下文 GetValueContext() model.ValueContext }
SDKContext . @brief SDK配置对象,每个API实例都会挂载一个context,包含: 插件实例列表 配置实例 执行流程引擎,包括定时器等
func InitContextByConfig ¶
func InitContextByConfig(cfg config.Configuration) (SDKContext, error)
InitContextByConfig InitContextByStream 通过配置对象新建上下文
func InitContextByFile ¶
func InitContextByFile(path string) (SDKContext, error)
InitContextByFile 通过配置文件新建服务消费者配置
func InitContextByStream ¶
func InitContextByStream(buf []byte) (SDKContext, error)
InitContextByStream 通过YAML流新建服务消费者配置
type SDKOwner ¶
type SDKOwner interface { // SDKContext 获取SDK上下文 SDKContext() SDKContext }
SDKOwner 获取SDK上下文接口
type ServiceCallResult ¶
type ServiceCallResult struct {
model.ServiceCallResult
}
ServiceCallResult 服务调用结果
type WatchAllInstancesRequest ¶ added in v1.4.0
type WatchAllInstancesRequest struct {
model.WatchAllInstancesRequest
}
WatchAllInstancesRequest .
type WatchAllServicesRequest ¶ added in v1.4.1
type WatchAllServicesRequest struct {
model.WatchAllServicesRequest
}
WatchAllServicesRequest .
type WatchServiceRequest ¶
type WatchServiceRequest struct {
model.WatchServiceRequest
}
WatchServiceRequest WatchService req