client

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: May 31, 2018 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package client is an interface for any protocol's client

Index

Constants

View Source
const DefaultPoolSize = 50

DefaultPoolSize is 500

Variables

This section is empty.

Functions

func GetProtocolSpec

func GetProtocolSpec(p string) model.Protocol

GetProtocolSpec is to get protocol specifications

func InstallPlugin

func InstallPlugin(protocol string, f NewFunc)

InstallPlugin is plugin for the new function

Types

type NewFunc

type NewFunc func(Options) ProtocolClient

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 {
	PoolSize  int
	PoolTTL   time.Duration
	TLSConfig *tls.Config
	Failure   map[string]bool
}

Options is configs for client creation

type ProtocolClient

type ProtocolClient interface {
	Call(ctx context.Context, addr string, req *Request, rsp interface{}) error
	String() string
}

ProtocolClient is the interface to communicate with one kind of ProtocolServer, it is used in transport handler rcp protocol client,http protocol client,or you can implement your own for example: rpc,it could be any client over any protocol,such as rpc over tcp ,rpc over http etc

func CreateClient

func CreateClient(protocol, service string) (ProtocolClient, error)

CreateClient is for to create client based on protocol and the service name

func GetClient

func GetClient(protocol, service string) (ProtocolClient, error)

GetClient is to get the client based on protocol and service name

type Request

type Request struct {
	ID               int
	MicroServiceName string
	Schema           string
	Operation        string
	Arg              interface{}
	Metadata         map[string]interface{}
}

Request is a struct for a protocol request to micro service server it includes common attribute for a protocol, usually, you should use Arg to wrap your real protocol request

func NewRequest

func NewRequest(service, schemaID, operationID string, arg interface{}) *Request

NewRequest create common request,you can operate it in you own Call method of a ProtocolClient

type Response

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

Response is a struct of micro service server response

Jump to

Keyboard shortcuts

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