Documentation
¶
Overview ¶
Package client is an interface for any protocol's client
Index ¶
- Constants
- Variables
- func Close(protocol, service, endpoint string) error
- func GetFailureMap(p string) map[string]bool
- func GetMaxIdleCon(p string) int
- func InstallPlugin(protocol string, f NewFunc)
- func ProcessSpecialProtocol(inv *invocation.Invocation)
- func ProcessSuccessiveFailure(i *invocation.Invocation)
- func SetTimeoutToClientCache(spec *model.IsolationWrapper)
- type NewFunc
- type Options
- type ProtocolClient
- type TransportFailure
- type TransportHandler
Constants ¶
const DefaultPoolSize = 512
DefaultPoolSize is 500
Variables ¶
var ErrCanceled = errors.New("request cancelled")
ErrCanceled means Request is canceled by context management
var ErrClientNotExist = errors.New("client not exists")
ErrClientNotExist happens if client do not exist
Functions ¶
func GetMaxIdleCon ¶
GetMaxIdleCon get max idle connection number you defined default is 512
func InstallPlugin ¶
InstallPlugin is plugin for the new function
func ProcessSpecialProtocol ¶ added in v2.1.1
func ProcessSpecialProtocol(inv *invocation.Invocation)
ProcessSpecialProtocol handles special logic for protocol
func ProcessSuccessiveFailure ¶ added in v2.1.1
func ProcessSuccessiveFailure(i *invocation.Invocation)
ProcessSuccessiveFailure handles special logic for protocol
func SetTimeoutToClientCache ¶
func SetTimeoutToClientCache(spec *model.IsolationWrapper)
SetTimeoutToClientCache set timeout to client
Types ¶
type NewFunc ¶
type NewFunc func(Options) (ProtocolClient, error)
NewFunc is function for the client
func GetClientNewFunc ¶
GetClientNewFunc is to get the client
type Options ¶
type Options struct { Service string PoolSize int Timeout time.Duration Endpoint string PoolTTL time.Duration TLSConfig *tls.Config Failure map[string]bool CheckRedirect func(req *http.Request, via []*http.Request) error }
Options is configs for client creation
type ProtocolClient ¶
type ProtocolClient interface { // TODO use invocation.Response as rsp // Call is the key function you must implement Call(ctx context.Context, addr string, inv *invocation.Invocation, rsp interface{}) error // if your protocol has response status(such as http return 200, 500 status code), // you need to return it according to response Status(rsp interface{}) (status int, err error) String() string Close() error // if you want to reload client settings on-fly, such as timeout, TLS config, // you need to implement it ReloadConfigs(Options) GetOptions() Options }
ProtocolClient is a interface to communicate with one kind of ProtocolServer, it is used in transport handler. this handler orchestrate client implementation. gRPC protocol client, http protocol client, or you can implement your own.
func CreateClient ¶
func CreateClient(protocol, service, endpoint string, sslEnable bool, checkRedirect func(req *http.Request, via []*http.Request) error) (ProtocolClient, error)
CreateClient is for to create client based on protocol and the service name
func GetClient ¶
func GetClient(i *invocation.Invocation) (ProtocolClient, error)
GetClient is to get the client based on protocol, service,endpoint name
type TransportFailure ¶
type TransportFailure struct {
Message string
}
TransportFailure is caused by client call failure for example: resp, err = client.Do(req) if err is not nil then should wrap original error with TransportFailure
type TransportHandler ¶ added in v2.1.1
type TransportHandler struct{}
TransportHandler transport handler
func (*TransportHandler) Handle ¶ added in v2.1.1
func (th *TransportHandler) Handle(chain *handler.Chain, i *invocation.Invocation, cb invocation.ResponseCallBack)
Handle is to handle transport related things
func (*TransportHandler) Name ¶ added in v2.1.1
func (th *TransportHandler) Name() string
Name returns transport string