client

package
v2.7.1 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2022 License: Apache-2.0 Imports: 17 Imported by: 4

Documentation

Overview

Package client is an interface for any protocol's client

Index

Constants

View Source
const DefaultPoolSize = 512

DefaultPoolSize is 500

Variables

View Source
var ErrCanceled = errors.New("request cancelled")

ErrCanceled means Request is canceled by context management

View Source
var ErrClientNotExist = errors.New("client not exists")

ErrClientNotExist happens if client do not exist

Functions

func Close

func Close(protocol, service, endpoint string) error

Close close a client conn

func GetFailureMap

func GetFailureMap(p string) map[string]bool

GetFailureMap return failure map

func GetMaxIdleCon

func GetMaxIdleCon(p string) int

GetMaxIdleCon get max idle connection number you defined default is 512

func InstallPlugin

func InstallPlugin(protocol string, f NewFunc)

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

func GetClientNewFunc(name string) (NewFunc, error)

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

func EqualOpts

func EqualOpts(oldOpts, newOpts Options) Options

EqualOpts equal newOpts and oldOpts

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

func (TransportFailure) Error

func (e TransportFailure) Error() string

Error return error message

type TransportHandler added in v2.1.1

type TransportHandler struct{}

TransportHandler transport handler

func (*TransportHandler) Handle added in v2.1.1

Handle is to handle transport related things

func (*TransportHandler) Name added in v2.1.1

func (th *TransportHandler) Name() string

Name returns transport string

Jump to

Keyboard shortcuts

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