Documentation ¶
Index ¶
- Variables
- func BuildTarget(target string, opts ...DialOption) (string, error)
- func ClosePolarisContext()
- func DialContext(ctx context.Context, target string, opts ...DialOption) (conn *grpc.ClientConn, err error)
- func NewResolver(ctx api.SDKContext) *resolverBuilder
- func PolarisConfig() config.Configuration
- func PolarisContext() (api.SDKContext, error)
- func RegisterResolverInterceptor(i ResolverInterceptor)
- func RequestScopeLbHashKey(ctx context.Context, key string) context.Context
- func RequestScopeLbPolicy(ctx context.Context, policy string) context.Context
- func Serve(gSrv *grpc.Server, lis net.Listener, opts ...ServerOption) error
- func SetLogger(logger Logger)
- func SetReportInfoAnalyzer(analyzer ReportInfoAnalyzer)
- type DelayStrategy
- type DialOption
- func WithClientNamespace(namespace string) DialOption
- func WithDisableCircuitBreaker() DialOption
- func WithDisableRouter() DialOption
- func WithDstMetadata(dstMetadata map[string]string) DialOption
- func WithEnableCircuitBreaker() DialOption
- func WithEnableRouter() DialOption
- func WithGRPCDialOptions(opts ...grpc.DialOption) DialOption
- func WithHeaderPrefix(headerPrefix []string) DialOption
- func WithPolarisConfig(polarisCfg config.Configuration) DialOption
- func WithPolarisContext(sdkContext api.SDKContext) DialOption
- func WithSrcMetadata(srcMetadata map[string]string) DialOption
- func WithSrcService(srcService string) DialOption
- type LBConfig
- type LogLevel
- type Logger
- type NoopDelayStrategy
- type RateLimitInterceptor
- func (p *RateLimitInterceptor) StreamServerInterceptor(srv interface{}, ss grpc.ServerStream, info *grpc.StreamServerInfo, ...) error
- func (p *RateLimitInterceptor) UnaryInterceptor(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, ...) (resp interface{}, err error)
- func (p *RateLimitInterceptor) WithNamespace(namespace string) *RateLimitInterceptor
- func (p *RateLimitInterceptor) WithServiceName(svcName string) *RateLimitInterceptor
- type ReportInfoAnalyzer
- type ResolverContext
- type ResolverInterceptor
- type Server
- type ServerOption
- func WithDelayRegisterEnable(strategy DelayStrategy) ServerOption
- func WithDelayStopDisable() ServerOption
- func WithDelayStopEnable(strategy DelayStrategy) ServerOption
- func WithGRPCServerOptions(opts ...grpc.ServerOption) ServerOption
- func WithGracefulStopDisable() ServerOption
- func WithGracefulStopEnable(duration time.Duration) ServerOption
- func WithHeartbeatEnable(enable bool) ServerOption
- func WithPolarisRateLimit() ServerOption
- func WithPort(port int) ServerOption
- func WithSDKContext(sdkContext api.SDKContext) ServerOption
- func WithServerApplication(application string) ServerOption
- func WithServerHost(host string) ServerOption
- func WithServerMetadata(metadata map[string]string) ServerOption
- func WithServerNamespace(namespace string) ServerOption
- func WithServerVersion(version string) ServerOption
- func WithServiceName(svcName string) ServerOption
- func WithTTL(ttl int) ServerOption
- func WithToken(token string) ServerOption
- type WaitDelayStrategy
Constants ¶
This section is empty.
Variables ¶
var ( // DefaultNamespace default namespace when namespace is not set DefaultNamespace = "default" // DefaultTTL default ttl value when ttl is not set DefaultTTL = 5 // DefaultGracefulStopMaxWaitDuration default stop max wait duration when not set DefaultGracefulStopMaxWaitDuration = 30 * time.Second // DefaultDelayStopWaitDuration default delay time before stop DefaultDelayStopWaitDuration = 4 * 2 * time.Second // MinGracefulStopWaitDuration low bound of stop wait duration MinGracefulStopWaitDuration = 5 * time.Second )
var ( // ErrorPolarisServiceRouteRuleEmpty error service route rule is empty ErrorPolarisServiceRouteRuleEmpty = errors.New("service route rule is empty") )
Functions ¶
func BuildTarget ¶
func BuildTarget(target string, opts ...DialOption) (string, error)
BuildTarget build the invoker grpc target Deprecated: will remove in 1.4
func ClosePolarisContext ¶ added in v1.5.0
func ClosePolarisContext()
func DialContext ¶
func DialContext(ctx context.Context, target string, opts ...DialOption) (conn *grpc.ClientConn, err error)
DialContext dial target and get connection
func NewResolver ¶ added in v1.5.0
func NewResolver(ctx api.SDKContext) *resolverBuilder
func PolarisConfig ¶
func PolarisConfig() config.Configuration
PolarisConfig get or init the global polaris configuration
func PolarisContext ¶
func PolarisContext() (api.SDKContext, error)
PolarisContext get or init the global polaris context
func RegisterResolverInterceptor ¶
func RegisterResolverInterceptor(i ResolverInterceptor)
RegisterResolverInterceptor NOTE: this function must only be called during initialization time (i.e. in an init() function), and is not thread-safe. If multiple RegisterInterceptor are registered with the same name, the one registered last will take effect.
func RequestScopeLbHashKey ¶
RequestScopeLbHashKey set request scope LbHashKey
func RequestScopeLbPolicy ¶
RequestScopeLbPolicy set request scope LbPolicy
func SetReportInfoAnalyzer ¶
func SetReportInfoAnalyzer(analyzer ReportInfoAnalyzer)
SetReportInfoAnalyzer sets report info analyzer
Types ¶
type DelayStrategy ¶
type DelayStrategy interface { // Allow delay strategy is allowed to continue to exec Allow() bool }
DelayStrategy delay register strategy. e.g. wait some time
type DialOption ¶
type DialOption interface {
// contains filtered or unexported methods
}
DialOption dialOptions for gRPC-Go-Polaris
func WithClientNamespace ¶
func WithClientNamespace(namespace string) DialOption
WithClientNamespace set the namespace for dial service
func WithDisableCircuitBreaker ¶
func WithDisableCircuitBreaker() DialOption
WithDisableCircuitBreaker close polaris circuitbreaker ability
func WithDisableRouter ¶
func WithDisableRouter() DialOption
WithDisableRouter close polaris route ability
func WithDstMetadata ¶
func WithDstMetadata(dstMetadata map[string]string) DialOption
WithDstMetadata set the dstMetadata for dial service routing
func WithEnableCircuitBreaker ¶
func WithEnableCircuitBreaker() DialOption
WithEnableCircuitBreaker open polaris circuitbreaker ability
func WithEnableRouter ¶
func WithEnableRouter() DialOption
WithEnableRouter open polaris route ability
func WithGRPCDialOptions ¶
func WithGRPCDialOptions(opts ...grpc.DialOption) DialOption
WithGRPCDialOptions set the raw gRPC dialOption
func WithHeaderPrefix ¶
func WithHeaderPrefix(headerPrefix []string) DialOption
WithHeaderPrefix set the header filter to get the header values to routing Deprecated: will remove in 1.4
func WithPolarisConfig ¶
func WithPolarisConfig(polarisCfg config.Configuration) DialOption
WithPolarisConfig set polaris configuration
func WithPolarisContext ¶
func WithPolarisContext(sdkContext api.SDKContext) DialOption
WithPolarisContext set polaris SDKContext
func WithSrcMetadata ¶
func WithSrcMetadata(srcMetadata map[string]string) DialOption
WithSrcMetadata set the srcMetadata for dial service routing Deprecated: will remove in 1.4
func WithSrcService ¶
func WithSrcService(srcService string) DialOption
WithSrcService set the srcMetadata for dial service routing
type LBConfig ¶
type LBConfig struct { serviceconfig.LoadBalancingConfig `json:"-"` HashKey string `json:"hash_key"` LbPolicy string `json:"lb_policy"` }
LBConfig is the LB config for the polaris policy.
type LogLevel ¶ added in v1.4.1
type LogLevel int
const ( LogDebug LogLevel LogInfo LogWarn LogError )
type Logger ¶ added in v1.4.1
type NoopDelayStrategy ¶
type NoopDelayStrategy struct{}
NoopDelayStrategy noop delay strategy
func (*NoopDelayStrategy) Allow ¶
func (d *NoopDelayStrategy) Allow() bool
Allow delay strategy is allowed to continue to exec
type RateLimitInterceptor ¶
type RateLimitInterceptor struct {
// contains filtered or unexported fields
}
RateLimitInterceptor is a gRPC interceptor that implements rate limiting.
func NewRateLimitInterceptor ¶
func NewRateLimitInterceptor() *RateLimitInterceptor
NewRateLimitInterceptor creates a new RateLimitInterceptor.
func (*RateLimitInterceptor) StreamServerInterceptor ¶ added in v1.5.0
func (p *RateLimitInterceptor) StreamServerInterceptor(srv interface{}, ss grpc.ServerStream, info *grpc.StreamServerInfo, handler grpc.StreamHandler) error
func (*RateLimitInterceptor) UnaryInterceptor ¶
func (p *RateLimitInterceptor) UnaryInterceptor(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (resp interface{}, err error)
UnaryInterceptor returns a unary interceptor for rate limiting.
func (*RateLimitInterceptor) WithNamespace ¶
func (p *RateLimitInterceptor) WithNamespace(namespace string) *RateLimitInterceptor
WithNamespace sets the namespace of the service.
func (*RateLimitInterceptor) WithServiceName ¶
func (p *RateLimitInterceptor) WithServiceName(svcName string) *RateLimitInterceptor
WithServiceName sets the service name.
type ReportInfoAnalyzer ¶
ReportInfoAnalyzer analyze balancer.DoneInfo to polaris report info
type ResolverContext ¶
type ResolverInterceptor ¶
type ResolverInterceptor interface {
After(ctx *ResolverContext, response *model.InstancesResponse) *model.InstancesResponse
}
ResolverInterceptor 从 polaris sdk 拉取完 instances 执行过滤
type Server ¶
Server encapsulated server with gRPC option
func NewServer ¶ added in v1.5.0
func NewServer(opts ...ServerOption) (*Server, error)
NewServer start polaris server
func (*Server) Deregister ¶
func (srv *Server) Deregister()
Deregister deregister services from polaris
type ServerOption ¶
type ServerOption interface {
// contains filtered or unexported methods
}
A ServerOption sets options such as credentials, codec and keepalive parameters, etc.
func WithDelayRegisterEnable ¶
func WithDelayRegisterEnable(strategy DelayStrategy) ServerOption
WithDelayRegisterEnable enables delay register
func WithDelayStopDisable ¶
func WithDelayStopDisable() ServerOption
WithDelayStopDisable disable delay stop Deprecated: will remove in 1.4
func WithDelayStopEnable ¶
func WithDelayStopEnable(strategy DelayStrategy) ServerOption
WithDelayStopEnable enables delay stop Deprecated: will remove in 1.4
func WithGRPCServerOptions ¶
func WithGRPCServerOptions(opts ...grpc.ServerOption) ServerOption
WithGRPCServerOptions set the raw gRPC serverOptions
func WithGracefulStopDisable ¶
func WithGracefulStopDisable() ServerOption
WithGracefulStopDisable disable graceful stop
func WithGracefulStopEnable ¶
func WithGracefulStopEnable(duration time.Duration) ServerOption
WithGracefulStopEnable enables graceful stop
func WithHeartbeatEnable ¶
func WithHeartbeatEnable(enable bool) ServerOption
WithHeartbeatEnable enables the heartbeat task to instance Deprecated: will remove in 1.4
func WithPolarisRateLimit ¶ added in v1.5.0
func WithPolarisRateLimit() ServerOption
WithPolarisLimit 开启北极星服务端限流能力
func WithPort ¶
func WithPort(port int) ServerOption
WithPort set the port to register instance 该方法非必需调用, 建议只在注册端口和程序实际监听端口需要不一致时才调用
func WithSDKContext ¶
func WithSDKContext(sdkContext api.SDKContext) ServerOption
WithSDKContext 设置用户自定义的北极星 SDKContext
func WithServerApplication ¶
func WithServerApplication(application string) ServerOption
WithServerApplication set application name Deprecated: use WithServiceName to replace WithServerApplication
func WithServerHost ¶
func WithServerHost(host string) ServerOption
WithServerHost set the host to register instance
func WithServerMetadata ¶
func WithServerMetadata(metadata map[string]string) ServerOption
WithServerMetadata set the metadata to register instance
func WithServerNamespace ¶
func WithServerNamespace(namespace string) ServerOption
WithServerNamespace set the namespace to register instance
func WithServerVersion ¶
func WithServerVersion(version string) ServerOption
WithServerVersion set the version to register instance
func WithServiceName ¶
func WithServiceName(svcName string) ServerOption
WithServiceName set the application to register instance
func WithToken ¶
func WithToken(token string) ServerOption
WithToken set the token to do server operations
type WaitDelayStrategy ¶
WaitDelayStrategy wait delay strategy
func (*WaitDelayStrategy) Allow ¶
func (d *WaitDelayStrategy) Allow() bool
Allow delay strategy is allowed to continue to exec