Documentation ¶
Index ¶
- Variables
- func NewClient(opt ...DialOption) (client *rpcClient)
- func RetryAlways(ctx context.Context, req Request, retryCount int, err error) (bool, error)
- type CallFunc
- type CallOption
- type CallOptions
- type CallWrapper
- type Conn
- type CreateConnectHandle
- type DialOption
- func RequestTimeout(timeout time.Duration) DialOption
- func Retries(retries int) DialOption
- func Retry(fn RetryFunc) DialOption
- func SetConnTimeout(timeout time.Duration) DialOption
- func SetPoolSize(size int) DialOption
- func SetPoolTTl(ttl time.Duration) DialOption
- func SetServer(name string, server *Server) DialOption
- func WithWrapCall(cw ...CallWrapper) DialOption
- type Message
- type Pool
- type PoolOptions
- type Request
- type RequestOption
- type RetryFunc
- type RpcClient
- type Server
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrNotServer = errors.New("查找不到服务配置信息") ErrPoolSize = errors.New("连接池大小不能小于0个") ErrAddrNotExist = errors.New("不存在服务地址") ErrPoolGetTimeout = errors.New("连接获取超时") ErrCreateConnHandleNotExit = errors.New("创建连接的处理方法不存在") ErrRequestTimeout = errors.New("请求超时") )
View Source
var ( // 默认连接池大小 DefaultPoolSize = 5 // 默认连接池生命周期 DefaultPoolTTl = 10 * time.Minute // 默认连接超时时间 DefaultConnTimeout = 3 * time.Second // 默认重试次数 DefaultRequestTimeout = 3 * time.Second // 默认重试次数 DefaultRetries = 1 // 默认重试验证方法 DefaultRetry = RetryAlways )
Functions ¶
Types ¶
type CallFunc ¶
type CallFunc func(ctx context.Context, req Request, rsp interface{}, opts CallOptions) error
CallFunc represents the individual call func
type CallOption ¶
type CallOption func(options *CallOptions)
func WrapCall ¶
func WrapCall(cw ...CallWrapper) CallOption
type CallOptions ¶
type CallOptions struct {
// contains filtered or unexported fields
}
type CallWrapper ¶
CallWrapper is a low level wrapper for the CallFunc
type Conn ¶
type Conn interface { // rpc调度服务方法 Call(ctx context.Context, req Request, resp interface{}, callOption CallOptions) error // 关闭连接 Close() error // 获取连接的创建时间 Created() time.Time // 获取连接的地址 Remote() string // 连接的异常记录 Error() error // 连接id Id() int64 }
运用接口可以方便后续升级和维护
type DialOption ¶
type DialOption interface {
// contains filtered or unexported methods
}
func WithWrapCall ¶
func WithWrapCall(cw ...CallWrapper) DialOption
type PoolOptions ¶
type PoolOptions struct { Id string Size int TTl time.Duration CreateConnectHandle }
连接池的配置信息
type Request ¶
type Request interface { // 服务名 Service() string // 请求方法 Method() string // 请求主题,也就是参数 Body() interface{} SetHeader(key string, value interface{}) Header() http.Header }
Request is the interface for a synchronous request used by Call or Stream
type RequestOption ¶
type RequestOption func(optiones *requestOptiones)
type RetryFunc ¶
note that returning either false or a non-nil error will result in the call not being retried
type RpcClient ¶
type RpcClient interface { ConnRelease(serverName string, conn Conn) NewConnect(serverName string) (Conn, error) Call(ctx context.Context, req Request, resp interface{}, callOption ...CallOption) error NewRequest(serverName string, serverMethod string, req interface{}, opts ...RequestOption) Request }
Click to show internal directories.
Click to hide internal directories.