client

package
v0.0.0-...-680e691 Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2021 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoInstances     = errors.New("no instances")
	ErrInvalidCallback = errors.New("invalid callback")
)

some error

Functions

func Decode

func Decode(rsp netx.Response, msg interface{}) error

Decode 解码消息

func NewRequest

func NewRequest(ctype netx.CodecType, msg interface{}) (netx.Request, error)

Types

type CallOption

type CallOption func(*CallOptions)

CallOption .

func WithCallTimeout

func WithCallTimeout(t time.Duration) CallOption

WithCallTimeout .

func WithCallback

func WithCallback(v interface{}) CallOption

WithCallback .

func WithDialTimeout

func WithDialTimeout(t time.Duration) CallOption

WithDialTimeout .

func WithRetryPolicy

func WithRetryPolicy(p RetryPolicy) CallOption

WithRetryPolicy .

type CallOptions

type CallOptions struct {
	DialTimeout time.Duration //
	CallTimeout time.Duration //
	Callback    interface{}   // 异步回调函数
	RetryPolicy RetryPolicy   // 重试策略
}

CallOptions Call时可选参数

type Caller

type Caller interface {
	Register(req netx.Request, callback netx.Callback, timeout time.Duration, retryer Retryer) error
	Unregister(seqId uint32)
	// Find 查询Callback,会自动注销
	Find(packet netx.Packet) netx.Callback
}

Caller 用于跟踪异步回调和超时处理

type Client

type Client interface {
	Call(ctx context.Context, req netx.Request, opts ...CallOption) (netx.Response, error)
	Close() error
}

Client .

func New

func New(opts ...Option) Client

New 创建client

type Configer

type Configer interface {
	GetDialTimeout(ctx context.Context, req netx.Request) time.Duration
	GetCallTimeout(ctx context.Context, req netx.Request) time.Duration
}

Configer 配置参数,可实现此接口从配置控制面获取相关配置

type ConnPool

type ConnPool interface {
	Get(ctx context.Context, ins discovery.Instance, tran netx.Tran, opts *CallOptions) (netx.Conn, error)
	Remove(ctx context.Context, ins discovery.Instance)
	Close() error
}

type Future

type Future interface {
	Add()
	Done(rsp netx.Response, err error)
	Wait() (netx.Response, error)
	Recycle()
}

Future 用于获取异步结果

func NewFuture

func NewFuture() Future

type Interceptor

type Interceptor interface {
	OnRequest(netx.Request) error
	OnResponse(netx.Response) error
	OnError(err error)
}

type Option

type Option func(*Options)

func WithBalancer

func WithBalancer(b loadbalance.Balancer) Option

func WithConfig

func WithConfig(v Configer) Option

func WithConnPool

func WithConnPool(p ConnPool) Option

func WithFailover

func WithFailover(v int) Option

func WithFilter

func WithFilter(v loadbalance.Filter) Option

func WithProtocol

func WithProtocol(p netx.Protocol) Option

func WithProxy

func WithProxy(p string) Option

func WithResolver

func WithResolver(r discovery.Resolver) Option

func WithTran

func WithTran(t netx.Tran) Option

type Options

type Options struct {
	Tran     netx.Tran            //
	Protocol netx.Protocol        // 默认编码协议
	Resolver discovery.Resolver   //
	Balancer loadbalance.Balancer //
	Filter   loadbalance.Filter   // 用于过滤
	Config   Configer             // 配置信息
	Proxy    string               // 代理服务名
	Failover int                  // 故障转移次数
	ConnPool ConnPool             //
	// contains filtered or unexported fields
}

Options 可选配置信息

type RetryPolicy

type RetryPolicy interface {
	Allow(ctx context.Context, req netx.Request, retryCount int) bool
}

RetryPolicy 重试策略,比如基于次数

type Retryer

type Retryer interface {
	Allow() bool
	Do(req netx.Request) error
	Recyle()
}

Retryer 重试回调

Directories

Path Synopsis
dns

Jump to

Keyboard shortcuts

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