Documentation ¶
Index ¶
- Variables
- func Logger() logger.ILogger
- func RetryAlways(ctx context.Context, req IRequest, retryCount int, err error) (bool, error)
- func RetryOnError(ctx context.Context, req IRequest, retryCount int, err error) (bool, error)
- type CallOption
- type CallOptions
- type Config
- type HttpClient
- func (self *HttpClient) Call(request *httpRequest, opts ...CallOption) (*httpResponse, error)
- func (self *HttpClient) Config() *Config
- func (self *HttpClient) CookiesManager() http.CookieJar
- func (self *HttpClient) Init(opts ...Option) error
- func (self *HttpClient) NewRequest(method, url string, data interface{}, optinos ...RequestOption) (*httpRequest, error)
- func (self *HttpClient) String() string
- type HttpOption
- type HttpRequest
- type IClient
- type IRequest
- type IResponse
- type Option
- func Debug() Option
- func WithConfigPrefixName(prefixName string) Option
- func WithHost(adr ...string) Option
- func WithHttpOptions(opts ...HttpOption) Option
- func WithJa3(ja3, userAgent string) Option
- func WithPrintRequest(all ...bool) Option
- func WithProxyURL(proxyURL string) Option
- func WithRegistries(typ string, Host string) Option
- func WithRegistry(r registry.IRegistry) Option
- func WithSerializeType(st codec.SerializeType) Option
- func WithTransport(t transport.ITransport) Option
- func WithTransportOptions(opts ...transport.Option) Option
- type RequestOption
- type RequestOptions
- type RetryFunc
- type RpcClient
- func (self *RpcClient) Call(request IRequest, opts ...CallOption) (IResponse, error)
- func (self *RpcClient) Config() *Config
- func (self *RpcClient) Init(opts ...Option) error
- func (self *RpcClient) NewRequest(service, method string, request interface{}, optinos ...RequestOption) (*rpcRequest, error)
- func (self *RpcClient) String() string
Constants ¶
This section is empty.
Variables ¶
var ( // DefaultRetry is the default check-for-retry function for retries DefaultRetry = RetryOnError // DefaultRetries is the default number of times a request is tried DefaultRetries = 1 // DefaultRequestTimeout is the default request timeout DefaultRequestTimeout = time.Second * 20 // DefaultPoolSize sets the connection pool size DefaultPoolSize = 100 // DefaultPoolTTL sets the connection pool ttl DefaultPoolTTL = time.Minute )
Functions ¶
func RetryAlways ¶
RetryAlways always retry on error
Types ¶
type CallOption ¶
type CallOption func(*CallOptions)
CallOption used by Call or Stream
func WithAddress ¶
func WithAddress(a ...string) CallOption
WithAddress sets the remote addresses to use rather than using service discovery
func WithContext ¶
func WithContext(ctx context.Context) CallOption
func WithRequestTimeout ¶
func WithRequestTimeout(d time.Duration) CallOption
WithRequestTimeout is a CallOption which overrides that which set in Options.CallOptions
type CallOptions ¶
type CallOptions struct { SelectOptions []selector.SelectOption // Address of remote hosts Address []string // Backoff func //Backoff BackoffFunc // Check if retriable func Retry RetryFunc // Transport Dial Timeout DialTimeout time.Duration // Number of Call attempts Retries int // Request/Response timeout RequestTimeout time.Duration // Stream timeout for the stream StreamTimeout time.Duration // Use the services own auth token ServiceToken bool // Duration to cache the response for CacheExpiry time.Duration // Other options for implementations of the interface // can be stored in a context Context context.Context }
type Config ¶
type Config struct { config.Config `field:"-"` Name string `field:"-"` // config name/path in config file PrefixName string `field:"-"` // config prefix name // Other options for implementations of the interface // can be stored in a context Logger logger.ILogger `field:"-"` // 保留:提供给扩展使用 Context context.Context `field:"-"` Client IClient `field:"-"` Transport transport.ITransport `field:"-"` Registry registry.IRegistry `field:"-"` Selector selector.ISelector `field:"-"` TlsConfig *tls.Config `field:"-"` // TLSConfig for tcp and quic CallOptions CallOptions `field:"-"` // Default Call Options DialOptions []transport.DialOption `field:"-"` // TODO // 提供实时变化sturct // Connection Pool PoolSize int PoolTtl time.Duration Retries int // Retries retries to send // Used to select codec ContentType string // Group is used to select the services in the same group. Services set group info in their meta. // If it is empty, clients will ignore group. Group string // BackupLatency is used for Failbackup mode. rpc will sends another request if the first response doesn't return in BackupLatency time. BackupLatency time.Duration // 传输序列类型 Serialize codec.SerializeType `field:"-"` SerializeType string //codec.SerializeType CompressType transport.CompressType Heartbeat bool HeartbeatInterval time.Duration Ja3 transport.Ja3 `field:"-"` ProxyUrl string // http options UserAgent string AllowRedirect bool // Debug mode PrintRequest bool PrintRequestAll bool // Registry RegistryType string RegistryHost string // Selector SelectorStrategy string // contains filtered or unexported fields }
type HttpClient ¶
type HttpClient struct {
// contains filtered or unexported fields
}
func NewHttpClient ¶
func NewHttpClient(opts ...Option) (*HttpClient, error)
func (*HttpClient) Call ¶
func (self *HttpClient) Call(request *httpRequest, opts ...CallOption) (*httpResponse, error)
阻塞请求
func (*HttpClient) Config ¶
func (self *HttpClient) Config() *Config
func (*HttpClient) CookiesManager ¶
func (self *HttpClient) CookiesManager() http.CookieJar
func (*HttpClient) Init ¶
func (self *HttpClient) Init(opts ...Option) error
func (*HttpClient) NewRequest ¶
func (self *HttpClient) NewRequest(method, url string, data interface{}, optinos ...RequestOption) (*httpRequest, error)
新建请求
func (*HttpClient) String ¶
func (self *HttpClient) String() string
type HttpOption ¶
type HttpOption func(*Config)
func AllowRedirect ¶
func AllowRedirect() HttpOption
func WithCookiejar ¶
func WithCookiejar(jar http.CookieJar) HttpOption
func WithUserAgent ¶
func WithUserAgent(userAgent string) HttpOption
type HttpRequest ¶
type HttpRequest = httpRequest
type IClient ¶
Client is the interface used to make requests to services. It supports Request/Response via Transport and Publishing via the Broker. It also supports bidirectional streaming of requests.
type IRequest ¶
type IRequest interface { // The service to call Service() string // The action to take Method() string // The endpoint to invoke //Endpoint() string // The content type ContentType() string Header() header.Header // The unencoded request body Body() *body.TBody // Write to the encoded request writer. This is nil before a call is made //Codec() codec.Writer // indicates whether the request will be a streaming one rather than unary Stream() bool }
Request is the interface for a synchronous request used by Call or Stream
type IResponse ¶
type IResponse interface { Body() *body.TBody // Read the response //Codec() codec.Reader // read the header Header() header.Header }
Response is the response received from a service
type Option ¶
type Option func(*Config)
Option contains all options for creating clients.
func WithHttpOptions ¶
func WithHttpOptions(opts ...HttpOption) Option
func WithProxyURL ¶
func WithRegistries ¶
func WithRegistry ¶
Registry to find nodes for a given service
func WithSerializeType ¶
func WithSerializeType(st codec.SerializeType) Option
Codec to be used to encode/decode requests for a given content type
func WithTransport ¶
func WithTransport(t transport.ITransport) Option
Transport to use for communication e.g http, rabbitmq, etc
func WithTransportOptions ¶
init transport
type RequestOption ¶
type RequestOption func(*RequestOptions)
RequestOption used by NewRequest
func Encoded ¶
func Encoded(on bool) RequestOption
func WithCodec ¶
func WithCodec(c codec.SerializeType) RequestOption
func WithServiceName ¶
func WithServiceName(name string) RequestOption
type RequestOptions ¶
type RetryFunc ¶
note that returning either false or a non-nil error will result in the call not being retried
type RpcClient ¶
type RpcClient struct {
// contains filtered or unexported fields
}
func NewRpcClient ¶
func (*RpcClient) Call ¶
func (self *RpcClient) Call(request IRequest, opts ...CallOption) (IResponse, error)
阻塞请求
func (*RpcClient) NewRequest ¶
func (self *RpcClient) NewRequest(service, method string, request interface{}, optinos ...RequestOption) (*rpcRequest, error)
新建请求