api

package
Version: v1.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 7, 2022 License: Apache-2.0, BSD-2-Clause, BSD-3-Clause, + 3 more Imports: 21 Imported by: 28

README

Polaris Go API方法使用

配置API

配置初始化
//使用默认配置对象来初始化配置,连接默认的北极星埋点域名
cfg := api.NewConfiguration()
修改北极星后端集群名
//先初始化配置
cfg := api.NewConfiguration()
//修改发现server集群名
cfg.GetGlobal().GetSystem().GetDiscoverCluster().SetService("polaris-server")
//修改心跳server集群名
cfg.GetGlobal().GetSystem().GetHealthCheckCluster().SetService("healthcheck")
//修改监控server集群名
cfg.GetGlobal().GetSystem().GetHealthCheckCluster().SetService("polaris.monitor")
修改北极星日志路径

假如需要修改北极星的日志打印目录,可以按照以下方式进行修改

if err := api.SetLoggersDir("/tmp/polaris/log"); err != nil {
   //do error handle
}
修改北极星日志级别

假如需要修改北极星的日志打印级别,可以按照以下方式进行修改

if err := api.SetLoggersLevel(api.InfoLog); err != nil {
    //do error handle
}

日志级别支持NoneLog, TraceLog, DebugLog, InfoLog, WarnLog, ErrorLog, FatalLog,设置成NoneLog,则不打印任何日志

同时修改北极星日志路径及日志级别

polaris-go启动后,默认会在程序运行的当前目录创建polaris/log目录,用于存放运行过程中的日志。因此用户需要保证当前目录有写权限 假如需要修改北极星的日志打印目录以及日志级别,可以按照以下方式进行修改

if err := api.ConfigLoggers("/tmp/polaris/log", api.InfoLog); err != nil {
    //do error handle
}

Documentation

Index

Constants

View Source
const (
	// LBPolicyWeightedRandom 权重随机负载均衡策略
	LBPolicyWeightedRandom = config.DefaultLoadBalancerWR
	// LBPolicyRingHash 权重一致性hash负载均衡策略
	LBPolicyRingHash = config.DefaultLoadBalancerRingHash
	// LBPolicyMaglev Maglev算法的一致性hash负载均衡策略
	LBPolicyMaglev = config.DefaultLoadBalancerMaglev
	// LBPolicyL5CST L5一致性Hash兼容算法,保证和L5产生相同的结果
	LBPolicyL5CST = config.DefaultLoadBalancerL5CST
)
View Source
const (
	// RetSuccess 调用成功
	RetSuccess = model.RetSuccess
	// RetFail 调用失败
	RetFail = model.RetFail
)
View Source
const (
	MeshVirtualService  = model.MeshVirtualService
	MeshServiceEntry    = model.MeshServiceEntry
	MeshDestinationRule = model.MeshDestinationRule
	MeshEnvoyFilter     = model.MeshEnvoyFilter
	MeshGateway         = model.MeshGateway
)

网格类型

View Source
const (
	// QuotaResultOk 限流状态值
	QuotaResultOk = model.QuotaResultOk
	// QuotaResultLimited 限流结果
	QuotaResultLimited = model.QuotaResultLimited
)
View Source
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
)

日志级别

View Source
const (
	// DefaultBaseLogLevel 默认基本日志级别
	DefaultBaseLogLevel = log.DefaultBaseLogLevel
	// DefaultStatLogLevel 默认统计日志级别
	DefaultStatLogLevel = log.DefaultStatLogLevel
	// DefaultDetectLogLevel 默认探测日志级别
	DefaultDetectLogLevel = log.DefaultDetectLogLevel
	// DefaultStatReportLogLevel 默认统计上报日志级别
	DefaultStatReportLogLevel = log.DefaultStatReportLogLevel
	// DefaultNetworkLogLevel 默认网络交互日志级别
	DefaultNetworkLogLevel = log.DefaultNetworkLogLevel
)
View Source
const (
	// EventInstance .
	EventInstance = model.EventInstance
)

Variables

View Source
var (
	// NewConfigFileAPIBySDKContext 通过 SDKContext 创建 ConfigFileAPI
	NewConfigFileAPIBySDKContext = newConfigFileAPIBySDKContext
	// NewConfigFileAPI 通过 polaris.yaml 创建 ConfigFileAPI
	NewConfigFileAPI = newConfigFileAPI
	// NewConfigFileAPIByConfig 通过 Configuration 创建 ConfigFileAPI
	NewConfigFileAPIByConfig = newConfigFileAPIByConfig
	// NewConfigFileAPIByFile 通过配置文件创建 ConfigFileAPI
	NewConfigFileAPIByFile = newConfigFileAPIByFile
)
View Source
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
)
View Source
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
)
View Source
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 ConfigBaseLogger

func ConfigBaseLogger(logDir string, logLevel int) error

ConfigBaseLogger 配置基础日志对象

func ConfigDetectLogger

func ConfigDetectLogger(logDir string, logLevel int) error

ConfigDetectLogger 配置探测日志对象

func ConfigLoggers

func ConfigLoggers(logDir string, logLevel int) error

ConfigLoggers 全局配置日志对象

func ConfigNetworkLogger

func ConfigNetworkLogger(logDir string, logLevel int) error

ConfigNetworkLogger 配置网络交互日志对象

func ConfigStatLogger

func ConfigStatLogger(logDir string, logLevel int) error

ConfigStatLogger 配置统计日志对象

func ConfigStatReportLogger

func ConfigStatReportLogger(logDir string, logLevel int) error

ConfigStatReportLogger 配置统计上报日志对象

func NewConfiguration

func NewConfiguration() config.Configuration

NewConfiguration 创建默认配置

func SetBaseLogger

func SetBaseLogger(logger Logger)

SetBaseLogger 设置基础日志对象

func SetDetectLogger

func SetDetectLogger(logger Logger)

SetDetectLogger 设置探测日志对象

func SetLoggersDir

func SetLoggersDir(logDir string) error

SetLoggersDir 设置日志的目录,会创建新的具有默认打印级别的logger

func SetLoggersLevel

func SetLoggersLevel(loglevel int) error

SetLoggersLevel 设置所有日志级别

func SetStatLogger

func SetStatLogger(logger Logger)

SetStatLogger 设置统计日志对象

func SetStatReportLogger

func SetStatReportLogger(logger Logger)

SetStatReportLogger 设置统计上报日志对象

Types

type ConfigFileAPI added in v1.1.0

type ConfigFileAPI interface {
	SDKOwner
	// GetConfigFile 获取配置文件
	GetConfigFile(namespace, fileGroup, fileName string) (model.ConfigFile, error)
}

ConfigFileAPI 配置文件的 API

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()
	// WatchService 订阅服务消息
	WatchService(req *WatchServiceRequest) (*model.WatchServiceResponse, error)
	// GetMeshConfig 同步获取网格规则
	GetMeshConfig(req *GetMeshConfigRequest) (*model.MeshConfigResponse, error)
	// GetMesh 同步获取网格
	GetMesh(req *GetMeshRequest) (*model.MeshResponse, error)
	// GetServicesByBusiness 根据业务同步获取批量服务
	GetServicesByBusiness(req *GetServicesRequest) (*model.ServicesResponse, error)
	// InitCalleeService 初始化服务运行中需要的被调服务
	InitCalleeService(req *InitCalleeServiceRequest) error
}

ConsumerAPI 主调端API方法

type GetAllInstancesRequest

type GetAllInstancesRequest struct {
	model.GetAllInstancesRequest
}

GetAllInstancesRequest 获取服务下所有实例的请求对象

type GetInstancesRequest

type GetInstancesRequest struct {
	model.GetInstancesRequest
}

GetInstancesRequest 获取多个服务的请求对象

type GetMeshConfigRequest

type GetMeshConfigRequest struct {
	model.GetMeshConfigRequest
}

GetMeshConfigRequest 获取网格规则请求

type GetMeshRequest

type GetMeshRequest struct {
	model.GetMeshRequest
}

GetMeshRequest 获取网格规则请求

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 实例请求

func (InstanceRequest) Validate

func (g InstanceRequest) Validate() error

Validate 校验实例请求对象

type LimitAPI

type LimitAPI interface {
	SDKOwner
	// GetQuota 获取限流配额,一次接口只获取一个配额
	GetQuota(request QuotaRequest) (QuotaFuture, error)
	// Destroy 销毁API,销毁后无法再进行调用
	Destroy()
}

LimitAPI 限流相关的API相关接口

type Logger

type Logger log.Logger

Logger 别名类

func GetBaseLogger

func GetBaseLogger() Logger

GetBaseLogger 获取基础日志对象

func GetDetectLogger

func GetDetectLogger() Logger

GetDetectLogger 获取探测日志对象

func GetStatLogger

func GetStatLogger() Logger

GetStatLogger 获取统计日志对象

func GetStatReportLogger

func GetStatReportLogger() Logger

GetStatReportLogger 获取统计上报日志对象

type ProviderAPI

type ProviderAPI interface {
	SDKOwner
	// Register
	// 同步注册服务,服务注册成功后会填充instance中的InstanceID字段
	// 用户可保持该instance对象用于反注册和心跳上报
	Register(instance *InstanceRegisterRequest) (*model.InstanceRegisterResponse, error)
	// Deregister
	// 同步反注册服务
	Deregister(instance *InstanceDeRegisterRequest) error
	// Heartbeat
	// 心跳上报
	Heartbeat(instance *InstanceHeartbeatRequest) error
	// Destroy
	// 销毁API,销毁后无法再进行调用
	Destroy()
}

ProviderAPI CL5服务端API的主接口

type QuotaFuture

type QuotaFuture interface {
	// Done 标识分配是否结束
	Done() <-chan struct{}
	// Get 获取分配结果
	Get() *model.QuotaResponse
	// Release 释放资源,仅用于并发数限流的场景
	Release()
}

QuotaFuture 实时/延时分配future

type QuotaRequest

type QuotaRequest interface {
	// SetNamespace 设置命名空间
	SetNamespace(string)
	// SetService 设置服务名
	SetService(string)
	// SetCluster 设置集群名
	SetCluster(string)
	// SetLabels 设置业务标签信息
	SetLabels(map[string]string)
	// SetTimeout 设置单次请求超时时间
	SetTimeout(timeout time.Duration)
	// SetRetryCount 设置最大重试次数
	SetRetryCount(retryCount int)
}

QuotaRequest 配额查询请求

func NewQuotaRequest

func NewQuotaRequest() QuotaRequest

NewQuotaRequest 创建配额查询请求

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 WatchServiceRequest

type WatchServiceRequest struct {
	model.WatchServiceRequest
}

WatchServiceRequest WatchService req

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL