Documentation
¶
Index ¶
- Constants
- Variables
- func BindMetadataForContext(ctx context.Context, data map[string]string) context.Context
- func NewClient(ctx context.Context, uri string, pbNewXxxClient interface{}, ...) (interface{}, error)
- func NewClientWithPool(ctx context.Context, pool *ConnPool, pbNewXxxClient interface{}) (interface{}, error)
- type ClientOptional
- func WithConnectionPool(pool *ConnPool) ClientOptional
- func WithDialOptions(options ...grpc.DialOption) ClientOptional
- func WithLoadBalance(loadBalance string) ClientOptional
- func WithLogger(logger *zap.Logger) ClientOptional
- func WithMetrics(metrics bool) ClientOptional
- func WithResolver(r resolver.Builder) ClientOptional
- func WithSecure(secure bool) ClientOptional
- func WithTimeout(t time.Duration) ClientOptional
- func WithTracer(tracer opentracing.Tracer) ClientOptional
- type ClientOptions
- type ConnPool
- type ConnPoolConfig
- type ConnPoolStats
- type HttpClient
- func (c *HttpClient) Get(ctx context.Context, path string, header http.Header, reqData url.Values, ...) (err error)
- func (c *HttpClient) GetRaw(ctx context.Context, path string, header http.Header, reqData url.Values) (rsp string, err error)
- func (c *HttpClient) Post(ctx context.Context, path string, header http.Header, reqData interface{}, ...) (err error)
- func (c *HttpClient) PostRaw(ctx context.Context, path string, header http.Header, reqData interface{}) (rsp string, err error)
- func (c *HttpClient) Request(ctx context.Context, method, path string, header http.Header, ...) (err error)
- type HttpClientOptional
- type HttpClientOptions
- type PooledClientConn
- type Resolver
Constants ¶
View Source
const ( // DefaultTimeout DefaultTimeout = time.Second * 10 // DefaultRetryTimes 如果请求失败,最多重试3次 DefaultRetryTimes = 3 // DefaultRetryDelay 在重试前,延迟等待100毫秒 DefaultRetryDelay = time.Millisecond * 100 RequestIDHeader = "X-Request-Id" )
View Source
const ( KiB MiB GiB TiB // DialTimeout the timeout of create connection DialTimeout = 5 * time.Second // BackoffMaxDelay provided maximum delay when backing off after failed connection attempts. BackoffMaxDelay = 3 * time.Second // MaxSendMsgSize set max gRPC request message size sent to server. // If any request message size is larger than current value, an error will be reported from gRPC. MaxSendMsgSize = 4 << 30 // MaxRecvMsgSize set max gRPC receive message size received from server. // If any message size is larger than current value, an error will be reported from gRPC. MaxRecvMsgSize = 4 << 30 // InitialWindowSize we set it 1GB is to provide system's throughput. InitialWindowSize = 1 << 30 // InitialConnWindowSize we set it 1GB is to provide system's throughput. InitialConnWindowSize = 1 << 30 )
Variables ¶
View Source
var ( ErrPoolClosed = errors.New("connection pool is closed") ErrNoConn = errors.New("no available connections") )
Functions ¶
func BindMetadataForContext ¶
BindMetadataForContext
Types ¶
type ClientOptional ¶
type ClientOptional func(o *ClientOptions)
ClientOptional
func WithConnectionPool ¶ added in v0.4.0
func WithConnectionPool(pool *ConnPool) ClientOptional
WithConnectionPool
func WithDialOptions ¶ added in v0.2.30
func WithDialOptions(options ...grpc.DialOption) ClientOptional
WithDialOptions
type ClientOptions ¶
type ClientOptions struct {
// contains filtered or unexported fields
}
ClientOptions
type ConnPool ¶ added in v0.4.0
type ConnPool struct {
// contains filtered or unexported fields
}
ConnPool gRPC连接池
func NewConnPool ¶ added in v0.4.0
func NewConnPool(config ConnPoolConfig) (*ConnPool, error)
NewConnPool 创建新的连接池
type ConnPoolConfig ¶ added in v0.4.0
type ConnPoolConfig struct {
Target string
MaxSize int
MinSize int
HealthCheckInterval time.Duration
Options []grpc.DialOption
}
ConnPoolConfig 连接池配置
type ConnPoolStats ¶ added in v0.4.0
type ConnPoolStats struct {
TotalConns int `json:"total_conns"`
ActiveConns int `json:"active_conns"`
IdleConns int `json:"idle_conns"`
TotalRequests int64 `json:"total_requests"`
TotalErrors int64 `json:"total_errors"`
}
ConnPoolStats 连接池统计信息
type HttpClient ¶ added in v0.2.30
type HttpClient struct {
// contains filtered or unexported fields
}
HttpClient
func NewHttpClient ¶ added in v0.2.30
func NewHttpClient(ctx context.Context, uri string, opts ...HttpClientOptional) (*HttpClient, error)
NewHttpClient
func (*HttpClient) Get ¶ added in v0.3.0
func (c *HttpClient) Get(ctx context.Context, path string, header http.Header, reqData url.Values, rspPtr interface{}) (err error)
Get
func (*HttpClient) GetRaw ¶ added in v0.3.0
func (c *HttpClient) GetRaw(ctx context.Context, path string, header http.Header, reqData url.Values) (rsp string, err error)
GetRaw
func (*HttpClient) Post ¶ added in v0.3.0
func (c *HttpClient) Post(ctx context.Context, path string, header http.Header, reqData interface{}, rspPtr interface{}) (err error)
Post
type HttpClientOptional ¶ added in v0.2.30
type HttpClientOptional func(o *HttpClientOptions)
ClientOptional
func WithHttpLogger ¶ added in v0.2.30
func WithHttpLogger(logger *zap.Logger) HttpClientOptional
WithHttpLogger
func WithHttpResolver ¶ added in v0.2.30
func WithHttpResolver(resolver Resolver) HttpClientOptional
WithHttpResolver
func WithHttpTracer ¶ added in v0.2.30
func WithHttpTracer(tracer opentracing.Tracer) HttpClientOptional
WithHttpTracer
func WithReqestTimeout ¶ added in v0.2.11
func WithReqestTimeout(t time.Duration) HttpClientOptional
WithReqestTimeout
type HttpClientOptions ¶ added in v0.2.30
type HttpClientOptions struct {
// contains filtered or unexported fields
}
HttpClientOptions
type PooledClientConn ¶ added in v0.4.0
type PooledClientConn struct {
*grpc.ClientConn
// contains filtered or unexported fields
}
PooledClientConn 池化连接包装器,实现自动归还
func (*PooledClientConn) Close ¶ added in v0.4.0
func (p *PooledClientConn) Close() error
Close 重写Close方法,实现连接归还而非关闭
Click to show internal directories.
Click to hide internal directories.