Documentation
¶
Index ¶
- Constants
- Variables
- func IsTemporaryError(err error) bool
- func IsTimeoutError(err error) bool
- func RegisterHandler(name string, handlerFactory HandlerFactory)
- func RegisterTransport(name string, transportFactory TransportFactory)
- func SeparatePluginHandlers(handlers []PluginHandler) (invokeHandlers []PluginHandler, ioHandlers []PluginHandler)
- func WithContext(ctx context.Context, rpcContext Context) context.Context
- type Client
- func (c *Client) Abort()
- func (c *Client) Call(ctx context.Context, name string, args []interface{}) (result []interface{}, err error)
- func (c *Client) GetTransport(name string) Transport
- func (c *Client) Invoke(name string, args []interface{}) (result []interface{}, err error)
- func (c *Client) InvokeContext(ctx context.Context, name string, args []interface{}) (result []interface{}, err error)
- func (c *Client) Request(ctx context.Context, request []byte) (response []byte, err error)
- func (c *Client) RequestHeaders() Dict
- func (c *Client) SetURI(uri ...string)
- func (c *Client) ShuffleURLs() *Client
- func (c *Client) Transport(ctx context.Context, request []byte) (response []byte, err error)
- func (c *Client) Unuse(handler ...PluginHandler) *Client
- func (c *Client) Use(handler ...PluginHandler) *Client
- func (c *Client) UseService(remoteService interface{}, namespace ...string)
- type ClientCodec
- type ClientContext
- type CodecOption
- func WithDebug(debug bool) CodecOption
- func WithListType(listType io.ListType) CodecOption
- func WithLongType(longType io.LongType) CodecOption
- func WithMapType(mapType io.MapType) CodecOption
- func WithRealType(realType io.RealType) CodecOption
- func WithSimple(simple bool) CodecOption
- func WithStructType(structType io.StructType) CodecOption
- type Context
- type Dict
- type Handler
- type HandlerFactory
- type IOHandler
- type InvalidRequestError
- type InvalidResponseError
- type InvocationHandler
- type InvokeHandler
- type Method
- type MethodManager
- type NextIOHandler
- type NextInvokeHandler
- type NextPluginHandler
- type PanicError
- type PluginHandler
- type PluginManager
- type ProxyBuilder
- type Server
- type Service
- func (s *Service) Add(method Method) *Service
- func (s *Service) AddAllMethods(target interface{}, namespace ...string) *Service
- func (s *Service) AddFunction(f interface{}, alias ...string) *Service
- func (s *Service) AddInstanceMethods(target interface{}, namespace ...string) *Service
- func (s *Service) AddMethod(name string, target interface{}, alias ...string) *Service
- func (s *Service) AddMethods(names []string, target interface{}, namespace ...string) *Service
- func (s *Service) AddMissingMethod(f interface{}) *Service
- func (s *Service) AddNetRPCMethods(rcvr interface{}, namespace ...string) *Service
- func (s *Service) Bind(server Server) error
- func (s *Service) BindContext(ctx context.Context, server Server) error
- func (s *Service) Execute(ctx context.Context, name string, args []interface{}) (result []interface{}, err error)
- func (s *Service) Get(name string) Method
- func (s *Service) GetHandler(name string) Handler
- func (s *Service) Handle(ctx context.Context, request []byte) ([]byte, error)
- func (mm *Service) Methods() (methods []Method)
- func (mm *Service) Names() (names []string)
- func (s *Service) Process(ctx context.Context, request []byte) ([]byte, error)
- func (s *Service) Remove(name string) *Service
- func (s *Service) Unuse(handler ...PluginHandler) *Service
- func (s *Service) Use(handler ...PluginHandler) *Service
- type ServiceCodec
- type ServiceContext
- type TagParser
- type Transport
- type TransportFactory
- type UnsupportedProtocolError
- type UnsupportedServerTypeError
- type WorkerPool
Constants ¶
const RequestEntityTooLarge = "Request entity too large"
RequestEntityTooLarge represents the error message of ErrRequestEntityTooLarge.
Variables ¶
var ErrClosed = errors.New("hprose/rpc/core: connection closed")
ErrClosed represents a error.
var ErrRequestEntityTooLarge = errors.New("hprose/rpc/core: request entity too large")
ErrRequestEntityTooLarge represents a error.
var ErrTimeout = timeoutError{}
ErrTimeout represents a error.
Functions ¶
func IsTemporaryError ¶
IsTemporaryError returns true if err is a temporary error.
func IsTimeoutError ¶
IsTimeoutError returns true if err is a timeout error.
func RegisterHandler ¶
func RegisterHandler(name string, handlerFactory HandlerFactory)
RegisterHandler for Service.
func RegisterTransport ¶
func RegisterTransport(name string, transportFactory TransportFactory)
RegisterTransport for Client.
func SeparatePluginHandlers ¶
func SeparatePluginHandlers(handlers []PluginHandler) (invokeHandlers []PluginHandler, ioHandlers []PluginHandler)
Types ¶
type Client ¶
type Client struct { Codec ClientCodec URLs []*url.URL Timeout time.Duration // contains filtered or unexported fields }
Client for RPC.
func (*Client) Call ¶
func (c *Client) Call(ctx context.Context, name string, args []interface{}) (result []interface{}, err error)
Call the remote method.
func (*Client) GetTransport ¶
GetTransport returns the transport by the specified name.
func (*Client) InvokeContext ¶
func (c *Client) InvokeContext(ctx context.Context, name string, args []interface{}) (result []interface{}, err error)
InvokeContext the remote method with context.Context.
func (*Client) RequestHeaders ¶
RequestHeaders returns the global request headers.
func (*Client) ShuffleURLs ¶
ShuffleURLs sorts the URLs in random order.
func (*Client) Unuse ¶
func (c *Client) Unuse(handler ...PluginHandler) *Client
Unuse plugin handlers.
func (*Client) UseService ¶
UseService build a remote service proxy object with namespace.
type ClientCodec ¶
type ClientCodec interface { Encode(name string, args []interface{}, context *ClientContext) (reqeust []byte, err error) Decode(response []byte, context *ClientContext) (result []interface{}, err error) }
ClientCodec for RPC.
func NewClientCodec ¶
func NewClientCodec(options ...CodecOption) ClientCodec
NewClientCodec returns the ClientCodec.
type ClientContext ¶
type ClientContext struct { Context URL *url.URL ReturnType []reflect.Type Timeout time.Duration // contains filtered or unexported fields }
ClientContext for RPC.
func GetClientContext ¶
func GetClientContext(ctx context.Context) *ClientContext
GetClientContext returns the *core.ClientContext bound to the context.
func NewClientContext ¶
func NewClientContext() *ClientContext
NewClientContext returns a core.ClientContext.
func (*ClientContext) Client ¶
func (c *ClientContext) Client() *Client
Client returns the Client reference.
func (*ClientContext) Clone ¶
func (c *ClientContext) Clone() Context
Clone returns a copy of this ClientContext.
type CodecOption ¶
type CodecOption func(interface{})
CodecOption for clientCodec & serviceCodec.
func WithDebug ¶
func WithDebug(debug bool) CodecOption
WithDebug returns a debug Option for clientCodec & serviceCodec.
func WithListType ¶ added in v3.0.15
func WithListType(listType io.ListType) CodecOption
WithListType returns a listType Option for clientCodec & serviceCodec.
func WithLongType ¶
func WithLongType(longType io.LongType) CodecOption
WithLongType returns a longType Option for clientCodec & serviceCodec.
func WithMapType ¶
func WithMapType(mapType io.MapType) CodecOption
WithMapType returns a mapType Option for clientCodec & serviceCodec.
func WithRealType ¶
func WithRealType(realType io.RealType) CodecOption
WithRealType returns a realType Option for clientCodec & serviceCodec.
func WithSimple ¶
func WithSimple(simple bool) CodecOption
WithSimple returns a simple Option for clientCodec & serviceCodec.
func WithStructType ¶ added in v3.0.15
func WithStructType(structType io.StructType) CodecOption
WithStructType returns a structType Option for clientCodec & serviceCodec.
type Context ¶
type Context interface { Items() Dict HasRequestHeaders() bool RequestHeaders() Dict HasResponseHeaders() bool ResponseHeaders() Dict Clone() Context }
Context for RPC.
func FromContext ¶
FromContext returns the core.Context bound to the context.
type Dict ¶
type Dict interface { Set(key string, value interface{}) Get(key string) (value interface{}, ok bool) GetInt(key string, defaultValue ...int) int GetUInt(key string, defaultValue ...uint) uint GetInt64(key string, defaultValue ...int64) int64 GetUInt64(key string, defaultValue ...uint64) uint64 GetFloat(key string, defaultValue ...float64) float64 GetBool(key string, defaultValue ...bool) bool GetString(key string, defaultValue ...string) string GetInterface(key string, defaultValue ...interface{}) interface{} Del(key string) Range(f func(key string, value interface{}) bool) Empty() bool CopyTo(dict Dict) ToMap() map[string]interface{} }
Dict represent the key-value pairs.
type HandlerFactory ¶
HandlerFactory is a constructor for Handler.
type IOHandler ¶
type IOHandler = func(ctx context.Context, request []byte, next NextIOHandler) (response []byte, err error)
IOHandler for RPC.
type InvalidRequestError ¶
type InvalidRequestError struct {
Request []byte
}
InvalidRequestError represents a error.
func (InvalidRequestError) Error ¶
func (e InvalidRequestError) Error() string
type InvalidResponseError ¶
type InvalidResponseError struct {
Response []byte
}
InvalidResponseError represents a error.
func (InvalidResponseError) Error ¶
func (e InvalidResponseError) Error() string
type InvocationHandler ¶
type InvocationHandler = func(proxy interface{}, method reflect.StructField, name string, args []interface{}) (results []interface{}, err error)
InvocationHandler for the proxy instance.
type InvokeHandler ¶
type InvokeHandler = func(ctx context.Context, name string, args []interface{}, next NextInvokeHandler) (result []interface{}, err error)
InvokeHandler for RPC.
type Method ¶
type Method interface { Func() reflect.Value Parameters() []reflect.Type Name() string Missing() bool PassContext() bool ReturnError() bool Options() Dict }
Method for RPC.
func MissingMethod ¶
func MissingMethod(f interface{}) Method
MissingMethod returns a missing Method object.
type MethodManager ¶
type MethodManager interface { Get(name string) Method Names() (names []string) Methods() (methods []Method) Remove(name string) Add(method Method) AddFunction(f interface{}, alias ...string) AddMethod(name string, target interface{}, alias ...string) AddMethods(names []string, target interface{}, namespace ...string) AddInstanceMethods(target interface{}, namespace ...string) AddAllMethods(target interface{}, namespace ...string) AddMissingMethod(f interface{}) AddNetRPCMethods(rcvr interface{}, namespace ...string) }
MethodManager for RPC.
func NewMethodManager ¶
func NewMethodManager() MethodManager
NewMethodManager returns a MethodManager.
type NextIOHandler ¶
NextIOHandler for RPC.
type NextInvokeHandler ¶
type NextInvokeHandler = func(ctx context.Context, name string, args []interface{}) (result []interface{}, err error)
NextInvokeHandler for RPC.
type NextPluginHandler ¶
type NextPluginHandler interface{}
NextPluginHandler must be one of NextInvokeHandler or NextIOHandler.
type PanicError ¶
type PanicError struct { Panic interface{} Stack []byte }
PanicError represents a panic error.
func NewPanicError ¶
func NewPanicError(v interface{}) *PanicError
NewPanicError return a panic error.
func (*PanicError) Error ¶
func (pe *PanicError) Error() string
Error implements the PanicError Error method.
func (*PanicError) String ¶
func (pe *PanicError) String() string
String returns the panic error message and stack.
type PluginHandler ¶
type PluginHandler interface{}
PluginHandler must be one of InvokeHandler or IOHandler.
type PluginManager ¶
type PluginManager interface { Handler() NextPluginHandler Use(handler ...PluginHandler) Unuse(handler ...PluginHandler) }
PluginManager for RPC.
func NewIOManager ¶
func NewIOManager(handler NextIOHandler) PluginManager
NewIOManager returns an IO PluginManager.
func NewInvokeManager ¶
func NewInvokeManager(handler NextInvokeHandler) PluginManager
NewInvokeManager returns an Invoke PluginManager.
type ProxyBuilder ¶
type ProxyBuilder interface {
Build(proxy interface{}, handler InvocationHandler)
}
ProxyBuilder .
var Proxy ProxyBuilder = proxyBuilder{}
Proxy is a global ProxyBuilder.
type Service ¶
type Service struct { Codec ServiceCodec MaxRequestLength int Options Dict // contains filtered or unexported fields }
Service for RPC.
func (*Service) AddAllMethods ¶
AddAllMethods will publish all methods and non-nil function fields on the obj self and on its anonymous or non-anonymous struct fields (or pointer to pointer ... to pointer struct fields). This is a recursive operation. So it's a pit, if you do not know what you are doing, do not step on.
func (*Service) AddFunction ¶
AddFunction is used for publishing function f with alias.
func (*Service) AddInstanceMethods ¶
AddInstanceMethods is used for publishing all the public methods and func fields with namespace.
func (*Service) AddMethod ¶
AddMethod is used for publishing method named name on target with alias.
func (*Service) AddMethods ¶
AddMethods is used for publishing methods named names on target with namespace.
func (*Service) AddMissingMethod ¶
AddMissingMethod is used for publishing a method, all methods not explicitly published will be redirected to this method.
func (*Service) AddNetRPCMethods ¶
AddNetRPCMethods is used for publishing methods defined for net/rpc.
func (*Service) BindContext ¶
BindContext to server with context.Context.
func (*Service) Execute ¶
func (s *Service) Execute(ctx context.Context, name string, args []interface{}) (result []interface{}, err error)
Execute the method and returns the results.
func (*Service) GetHandler ¶
GetHandler returns the handler by the specified name.
func (*Service) Unuse ¶
func (s *Service) Unuse(handler ...PluginHandler) *Service
Unuse plugin handlers.
type ServiceCodec ¶
type ServiceCodec interface { Encode(result interface{}, context *ServiceContext) (response []byte, err error) Decode(request []byte, context *ServiceContext) (name string, args []interface{}, err error) }
ServiceCodec for RPC.
func NewServiceCodec ¶
func NewServiceCodec(options ...CodecOption) ServiceCodec
NewServiceCodec returns the ServiceCodec.
type ServiceContext ¶
type ServiceContext struct { Context Method Method LocalAddr net.Addr RemoteAddr net.Addr Handler Handler // contains filtered or unexported fields }
ServiceContext for RPC.
func GetServiceContext ¶
func GetServiceContext(ctx context.Context) *ServiceContext
GetServiceContext returns the *core.ServiceContext bound to the context.
func NewServiceContext ¶
func NewServiceContext(service *Service) *ServiceContext
NewServiceContext returns a core.ServiceContext.
func (*ServiceContext) Clone ¶
func (c *ServiceContext) Clone() Context
Clone returns a copy of this ServiceContext.
func (*ServiceContext) Service ¶
func (c *ServiceContext) Service() *Service
Service returns the Service reference.
type TagParser ¶
type TagParser struct { Name string Context *ClientContext // contains filtered or unexported fields }
TagParser for Client Proxy.
type Transport ¶
type Transport interface { Transport(ctx context.Context, request []byte) (response []byte, err error) Abort() }
Transport is an interface used to represent client transport layer.
type TransportFactory ¶
TransportFactory is a constructor for Transport.
type UnsupportedProtocolError ¶
type UnsupportedProtocolError struct {
Scheme string
}
UnsupportedProtocolError represents a error.
func (UnsupportedProtocolError) Error ¶
func (e UnsupportedProtocolError) Error() string
type UnsupportedServerTypeError ¶
UnsupportedServerTypeError represents a error.
func (UnsupportedServerTypeError) Error ¶
func (e UnsupportedServerTypeError) Error() string
type WorkerPool ¶ added in v3.0.11
type WorkerPool interface {
Submit(func())
}