client

package
Version: v0.0.0-...-5dc8409 Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2018 License: Apache-2.0, Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package client is an interface for any protocol's client

Index

Constants

This section is empty.

Variables

View Source
var (
	// DefaultRetries is the default number of times a request is tried
	DefaultRetries = 1
	// DefaultRequestTimeout is the default request timeout
	DefaultRequestTimeout = time.Second * 5
	// DefaultPoolSize sets the connection pool size
	DefaultPoolSize = 50
	// DefaultPoolTTL sets the connection pool ttl
	DefaultPoolTTL = time.Minute
)

Functions

This section is empty.

Types

type CallOption

type CallOption func(*CallOptions)

CallOption used by Call or Stream

func WithContentType

func WithContentType(ct string) CallOption

func WithDialTimeout

func WithDialTimeout(d time.Duration) CallOption

WithDialTimeout is a CallOption which overrides that which set in Options.CallOptions

func WithMethodType

func WithMethodType(s string) CallOption

func WithRequestTimeout

func WithRequestTimeout(d time.Duration) CallOption

WithRequestTimeout is a CallOption which overrides that which set in Options.CallOptions

func WithRetries

func WithRetries(i int) CallOption

WithRetries is a CallOption which overrides that which set in Options.CallOptions

func WithUrlPath

func WithUrlPath(s string) CallOption

type CallOptions

type CallOptions struct {
	Message     []byte
	ContentType string
	// Transport Dial Timeout
	DialTimeout time.Duration
	// Number of Call attempts
	Retries int
	// Request/Response timeout
	RequestTimeout time.Duration

	// Other options for implementations of the interface
	// can be stored in a context
	Context    context.Context
	Header     map[string]string
	UrlPath    string
	MethodType string
}

type Client

type Client interface {
	Init(...Option) error
	Options() Options
	NewRequest(service, schemaID, operationID string, arg interface{}, reqOpts ...RequestOption) *Request
	Call(ctx context.Context, addr string, req *Request, rsp interface{}, opts ...CallOption) error
	String() string
}

Client is the interface used to make requests to services. It supports Request/Response via Transport rcp client,rest client,or you can implement your own for rpc,it could be any client over any protocol,such as rpc over tcp ,rpc over http etc

type Option

type Option func(*Options)

Option used by the Client

func ContentType

func ContentType(ct string) Option

Default content type of the client

func DialTimeout

func DialTimeout(d time.Duration) Option

Transport dial timeout

func PoolSize

func PoolSize(d int) Option

PoolSize sets the connection pool size

func PoolTTL

func PoolTTL(d time.Duration) Option

PoolSize sets the connection pool size

func RequestTimeout

func RequestTimeout(d time.Duration) Option

The request timeout. Should this be a Call Option?

func Retries

func Retries(i int) Option

Number of retries when making the request. Should this be a Call Option?

func TLSConfig

func TLSConfig(t *tls.Config) Option

func Transport

func Transport(t microTransport.Transport) Option

Transport to use for communication e.g http, rabbitmq, etc

func WithCodecs

func WithCodecs(c map[string]codec.Codec) Option

WithCodecs set Codecs

func WithConnectionPoolSize

func WithConnectionPoolSize(n int) Option

func WithFailure

func WithFailure(m map[string]bool) Option

type Options

type Options struct {
	// Used to select codec
	ContentType string

	// Plugged interfaces
	Codecs map[string]codec.Codec
	//TODO
	ClientCodecs map[string]codec.NewClientCodec
	Transport    microTransport.Transport

	// Connection Pool
	PoolSize int
	PoolTTL  time.Duration

	// Default Call Options
	CallOptions CallOptions

	// Other options for implementations of the interface
	// can be stored in a context
	Context   context.Context
	TLSConfig *tls.Config
	Failure   map[string]bool
}

type PublishOptions

type PublishOptions struct {
	// Other options for implementations of the interface
	// can be stored in a context
	Context context.Context
}

type Request

type Request struct {
	ID               int
	MicroServiceName string
	Struct           string
	Method           string
	Arg              interface{}
	Metadata         map[string]interface{}
}

Request is a struct for request APIs of micro service

type RequestOption

type RequestOption func(*RequestOptions)

type RequestOptions

type RequestOptions struct {
	Stream bool
	// Transport Dial Timeout
	DialTimeout time.Duration
	// Request/Response timeout
	RequestTimeout time.Duration
	// Other options for implementations of the interface
	// can be stored in a context
	Context context.Context
}

type Response

type Response struct {
	ID       int
	Error    string
	Reply    interface{}
	Metadata map[string]interface{}
}

Response is a struct of microservice response APIs

Jump to

Keyboard shortcuts

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