client

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2023 License: BSD-3-Clause Imports: 36 Imported by: 0

Documentation

Index

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

This section is empty.

Functions

func BindMetadataForContext

func BindMetadataForContext(ctx context.Context, data map[string]string) context.Context

BindMetadataForContext

func NewClient

func NewClient(ctx context.Context, uri string, pbNewXxxClient interface{},
	opts ...ClientOptional) (interface{}, error)

NewClient 参数 bNewXxxClient 对应 pb.NewXxxClient 方法

Types

type ClientOptional

type ClientOptional func(o *ClientOptions)

ClientOptional

func WithDialOptions added in v0.2.30

func WithDialOptions(options ...grpc.DialOption) ClientOptional

WithDialOptions

func WithLoadBalance

func WithLoadBalance(loadBalance string) ClientOptional

WithLoadBalance

func WithLogger

func WithLogger(logger *zap.Logger) ClientOptional

WithLogger

func WithMetrics

func WithMetrics(metrics bool) ClientOptional

WithMetrics

func WithResolver

func WithResolver(r resolver.Builder) ClientOptional

WithResolver

func WithSecure

func WithSecure(secure bool) ClientOptional

WithSecure

func WithTimeout

func WithTimeout(t time.Duration) ClientOptional

WithTimeout

func WithTracer

func WithTracer(tracer opentracing.Tracer) ClientOptional

WithTracer

type ClientOptions

type ClientOptions struct {
	// contains filtered or unexported fields
}

ClientOptions

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

func (*HttpClient) PostRaw added in v0.3.0

func (c *HttpClient) PostRaw(ctx context.Context, path string, header http.Header,
	reqData interface{}) (rsp string, err error)

PostRaw

func (*HttpClient) Request added in v0.2.30

func (c *HttpClient) Request(ctx context.Context, method,
	path string, header http.Header, reqData interface{},
	respDataPtr interface{},
) (err error)

Request 自动序列化和反序列化地请求 请求 和 响应 支持 struct 和 string 和 []byte 三种方式

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

func WithRetryTimes

func WithRetryTimes(retryTimes int) HttpClientOptional

WithRetryTimes 设置失败重试

type HttpClientOptions added in v0.2.30

type HttpClientOptions struct {
	// contains filtered or unexported fields
}

HttpClientOptions

type Resolver

type Resolver func(ctx context.Context, service string, tags []string) (addr string, err error)

Resolver resolver the host

Jump to

Keyboard shortcuts

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