{"modulePath":"github.com/LIU-RUI/RPCX","version":"v0.0.0-20160621091308-8216691ab069","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package rpcx\n\n## Constants\n\n```go\nconst (\n\t//DefaultRPCPath is the defaut HTTP RPC PATH\n\tDefaultRPCPath = \"/_goRPC_\"\n)\n```\n\n## Variables\n\n```go\nvar (\n\t// ErrPluginAlreadyExists returns an error with message: 'Cannot activate the same plugin again, plugin '+plugin name[+plugin description]' is already exists'\n\tErrPluginAlreadyExists = NewRPCError(\"Cannot use the same plugin again, '%s[%s]' is already exists\")\n\t// ErrPluginActivate returns an error with message: 'While trying to activate plugin '+plugin name'. Trace: +specific error'\n\tErrPluginActivate = NewRPCError(\"While trying to activate plugin '%s'. Trace: %s\")\n\t// ErrPluginRemoveNoPlugins returns an error with message: 'No plugins are registed yet, you cannot remove a plugin from an empty list!'\n\tErrPluginRemoveNoPlugins = NewRPCError(\"No plugins are registed yet, you cannot remove a plugin from an empty list!\")\n\t// ErrPluginRemoveEmptyName returns an error with message: 'Plugin with an empty name cannot be removed'\n\tErrPluginRemoveEmptyName = NewRPCError(\"Plugin with an empty name cannot be removed\")\n\t// ErrPluginRemoveNotFound returns an error with message: 'Cannot remove a plugin which doesn't exists'\n\tErrPluginRemoveNotFound = NewRPCError(\"Cannot remove a plugin which doesn't exists\")\n)\n```\n\n## Functions\n\n```go\nfunc Auth(fn AuthorizationFunc) error\n```\nAuth sets authorization handler\n\n```go\nfunc Close() error\n```\nClose closes RPC server.\n\n```go\nfunc GetListenedAddress() string\n```\nGetListenedAddress return the listening address.\n\n```go\nfunc NewDirectHTTPRPCClient(c *Client, clientCodecFunc ClientCodecFunc, network, address string, path string, timeout time.Duration) (*rpc.Client, error)\n```\nNewDirectHTTPRPCClient creates a rpc http client\n\n```go\nfunc NewDirectRPCClient(c *Client, clientCodecFunc ClientCodecFunc, network, address string, timeout time.Duration) (*rpc.Client, error)\n```\nNewDirectRPCClient creates a rpc client\n\n```go\nfunc RegisterName(name string, service interface{})\n```\nRegisterName publishes in the server the set of methods .\n\n```go\nfunc Serve(n, address string)\n```\nServe starts and listens RCP requests. It is blocked until receiving connectings from clients.\n\n```go\nfunc ServeByHTTP(ln net.Listener, rpcPath, debugPath string)\n```\nServeByHTTP implements RPC via HTTP\n\n```go\nfunc ServeListener(ln net.Listener)\n```\nServeListener serve with a listener\n\n```go\nfunc ServeTLS(n, address string, config *tls.Config)\n```\nServeTLS starts and listens RCP requests. It is blocked until receiving connectings from clients.\n\n```go\nfunc SetServerCodecFunc(fn ServerCodecFunc)\n```\nSetServerCodecFunc sets a ServerCodecFunc\n\n```go\nfunc Start(n, address string)\n```\nStart starts and listens RCP requests without blocking.\n\n```go\nfunc StartTLS(n, address string, config *tls.Config)\n```\nStartTLS starts and listens RCP requests without blocking.\n\n## Types\n\n```go\ntype AuthorizationAndServiceMethod struct {\n\tAuthorization string // Authorization\n\tServiceMethod string // real ServiceMethod name\n\tTag           string // extra tag for Authorization\n}\n```\nAuthorizationAndServiceMethod represents Authorization header and ServiceMethod.\n\n```go\ntype AuthorizationClientPlugin struct {\n\tAuthorizationAndServiceMethod *AuthorizationAndServiceMethod\n}\n```\nAuthorizationClientPlugin is used to set Authorization info at client side.\n\n```go\nfunc NewAuthorizationClientPlugin(authorization, tag string) *AuthorizationClientPlugin\n```\nNewAuthorizationClientPlugin creates a AuthorizationClientPlugin with authorization header and tag\n\n```go\nfunc (plugin *AuthorizationClientPlugin) Description() string\n```\nDescription return description of this plugin.\n\n```go\nfunc (plugin *AuthorizationClientPlugin) Name() string\n```\nName return name of this plugin.\n\n```go\nfunc (plugin *AuthorizationClientPlugin) PreWriteRequest(r *rpc.Request, body interface{}) error\n```\nPreWriteRequest adds Authorization info in requests\n\n```go\ntype AuthorizationFunc func(p *AuthorizationAndServiceMethod) error\n```\nAuthorizationFunc defines a method type which handles Authorization info\n\n```go\ntype AuthorizationServerPlugin struct {\n\tAuthorizationFunc AuthorizationFunc\n}\n```\nAuthorizationServerPlugin is used to authorize clients.\n\n```go\nfunc (plugin *AuthorizationServerPlugin) Description() string\n```\nDescription return description of this plugin.\n\n```go\nfunc (plugin *AuthorizationServerPlugin) Name() string\n```\nName return name of this plugin.\n\n```go\nfunc (plugin *AuthorizationServerPlugin) PostReadRequestHeader(r *rpc.Request) (err error)\n```\nPostReadRequestHeader extracts Authorization header from ServiceMethod field.\n\n```go\ntype Client struct {\n\tClientSelector  ClientSelector\n\tClientCodecFunc ClientCodecFunc\n\tPluginContainer IClientPluginContainer\n\tFailMode        FailMode\n\tTLSConfig       *tls.Config\n\tRetries         int\n\t// contains filtered or unexported fields\n}\n```\nClient represents a RPC client.\n\n```go\nfunc NewClient(s ClientSelector) *Client\n```\nNewClient create a client.\n\n```go\nfunc (c *Client) Auth(authorization, tag string) error\n```\nAuth sets Authorization info\n\n```go\nfunc (c *Client) Call(serviceMethod string, args interface{}, reply interface{}) (err error)\n```\nCall invokes the named function, waits for it to complete, and returns its error status.\n\n```go\nfunc (c *Client) Close() error\n```\nClose closes the connection\n\n```go\nfunc (c *Client) Go(serviceMethod string, args interface{}, reply interface{}, done chan *rpc.Call) *rpc.Call\n```\nGo invokes the function asynchronously. It returns the Call structure representing the invocation. The done channel will signal when the call is complete by returning the same Call object. If done is nil, Go will allocate a new channel. If non-nil, done must be buffered or Go will deliberately crash.\n\n```go\ntype ClientCodecFunc func(conn io.ReadWriteCloser) rpc.ClientCodec\n```\nClientCodecFunc is used to create a rpc.ClientCodecFunc from net.Conn.\n\n```go\ntype ClientPluginContainer struct {\n\t// contains filtered or unexported fields\n}\n```\nClientPluginContainer implements IPluginContainer interface.\n\n```go\nfunc (p *ClientPluginContainer) Add(plugin IPlugin) error\n```\nAdd adds a plugin.\n\n```go\nfunc (p *ClientPluginContainer) DoPostReadResponseBody(body interface{}) error\n```\nDoPostReadResponseBody invokes DoPostReadResponseBody plugin.\n\n```go\nfunc (p *ClientPluginContainer) DoPostReadResponseHeader(r *rpc.Response) error\n```\nDoPostReadResponseHeader invokes DoPostReadResponseHeader plugin.\n\n```go\nfunc (p *ClientPluginContainer) DoPostWriteRequest(r *rpc.Request, body interface{}) error\n```\nDoPostWriteRequest invokes DoPostWriteRequest plugin.\n\n```go\nfunc (p *ClientPluginContainer) DoPreReadResponseBody(body interface{}) error\n```\nDoPreReadResponseBody invokes DoPreReadResponseBody plugin.\n\n```go\nfunc (p *ClientPluginContainer) DoPreReadResponseHeader(r *rpc.Response) error\n```\nDoPreReadResponseHeader invokes DoPreReadResponseHeader plugin.\n\n```go\nfunc (p *ClientPluginContainer) DoPreWriteRequest(r *rpc.Request, body interface{}) error\n```\nDoPreWriteRequest invokes DoPreWriteRequest plugin.\n\n```go\nfunc (p *ClientPluginContainer) GetAll() []IPlugin\n```\nGetAll returns all activated plugins\n\n```go\nfunc (p *ClientPluginContainer) GetByName(pluginName string) IPlugin\n```\nGetByName returns a plugin instance by it's name\n\n```go\nfunc (p *ClientPluginContainer) GetDescription(plugin IPlugin) string\n```\nGetDescription returns the name of a plugin, if no GetDescription() implemented it returns an empty string \"\"\n\n```go\nfunc (p *ClientPluginContainer) GetName(plugin IPlugin) string\n```\nGetName returns the name of a plugin, if no GetName() implemented it returns an empty string \"\"\n\n```go\nfunc (p *ClientPluginContainer) Remove(pluginName string) error\n```\nRemove removes a plugin by it's name.\n\n```go\ntype ClientSelector interface {\n\tSelect(clientCodecFunc ClientCodecFunc, options ...interface{}) (*rpc.Client, error)\n\tSetClient(*Client)\n}\n```\nClientSelector defines an interface to create a rpc.Client from cluster or standalone.\n\n```go\ntype DirectClientSelector struct {\n\tNetwork, Address string\n\tTimeout          time.Duration\n\tClient           *Client\n}\n```\nDirectClientSelector is used to a direct rpc server. It don't select a node from service cluster but a specific rpc server.\n\n```go\nfunc (s *DirectClientSelector) Select(clientCodecFunc ClientCodecFunc, options ...interface{}) (*rpc.Client, error)\n```\nSelect returns a rpc client\n\n```go\nfunc (s *DirectClientSelector) SetClient(c *Client)\n```\n\n```go\ntype FailMode int\n```\nFailMode is a feature to decide client actions when clients fail to invoke services\n\n```go\nconst (\n\t//Failover selects another server automaticaly\n\tFailover FailMode = iota\n\t//Failfast returns error immediately\n\tFailfast\n\t//Failtry use current client again\n\tFailtry\n)\n```\n\n```go\ntype IClientPluginContainer interface {\n\tAdd(plugin IPlugin) error\n\tRemove(pluginName string) error\n\tGetName(plugin IPlugin) string\n\tGetDescription(plugin IPlugin) string\n\tGetByName(pluginName string) IPlugin\n\tGetAll() []IPlugin\n\n\tDoPreReadResponseHeader(*rpc.Response) error\n\tDoPostReadResponseHeader(*rpc.Response) error\n\tDoPreReadResponseBody(interface{}) error\n\tDoPostReadResponseBody(interface{}) error\n\n\tDoPreWriteRequest(*rpc.Request, interface{}) error\n\tDoPostWriteRequest(*rpc.Request, interface{}) error\n}\n```\nIClientPluginContainer represents a plugin container that defines all methods to manage plugins. And it also defines all extension points.\n\n```go\ntype IPlugin interface {\n\tName() string\n\tDescription() string\n}\n```\nIPlugin represents a plugin.\n\n```go\ntype IPostConnAcceptPlugin interface {\n\tHandleConnAccept(net.Conn) bool\n}\n```\nIPostConnAcceptPlugin represents connection accept plugin. if returns false, it means subsequent IPostConnAcceptPlugins should not contiune to handle this conn and this conn has been closed.\n\n```go\ntype IPostReadRequestBodyPlugin interface {\n\tPostReadRequestBody(body interface{}) error\n}\n```\nIPostReadRequestBodyPlugin represents .\n\n```go\ntype IPostReadRequestHeaderPlugin interface {\n\tPostReadRequestHeader(r *rpc.Request) error\n}\n```\nIPostReadRequestHeaderPlugin represents .\n\n```go\ntype IPostReadResponseBodyPlugin interface {\n\tPostReadResponseBody(interface{}) error\n}\n```\nIPostReadResponseBodyPlugin represents .\n\n```go\ntype IPostReadResponseHeaderPlugin interface {\n\tPostReadResponseHeader(*rpc.Response) error\n}\n```\nIPostReadResponseHeaderPlugin represents .\n\n```go\ntype IPostWriteRequestPlugin interface {\n\tPostWriteRequest(*rpc.Request, interface{}) error\n}\n```\nIPostWriteRequestPlugin represents .\n\n```go\ntype IPostWriteResponsePlugin interface {\n\tPostWriteResponse(*rpc.Response, interface{}) error\n}\n```\nIPostWriteResponsePlugin represents .\n\n```go\ntype IPreReadRequestBodyPlugin interface {\n\tPreReadRequestBody(body interface{}) error\n}\n```\nIPreReadRequestBodyPlugin represents .\n\n```go\ntype IPreReadRequestHeaderPlugin interface {\n\tPreReadRequestHeader(r *rpc.Request) error\n}\n```\nIPreReadRequestHeaderPlugin represents .\n\n```go\ntype IPreReadResponseBodyPlugin interface {\n\tPreReadResponseBody(interface{}) error\n}\n```\nIPreReadResponseBodyPlugin represents .\n\n```go\ntype IPreReadResponseHeaderPlugin interface {\n\tPreReadResponseHeader(*rpc.Response) error\n}\n```\nIPreReadResponseHeaderPlugin represents .\n\n```go\ntype IPreWriteRequestPlugin interface {\n\tPreWriteRequest(*rpc.Request, interface{}) error\n}\n```\nIPreWriteRequestPlugin represents .\n\n```go\ntype IPreWriteResponsePlugin interface {\n\tPreWriteResponse(*rpc.Response, interface{}) error\n}\n```\nIPreWriteResponsePlugin represents .\n\n```go\ntype IRegisterPlugin interface {\n\tRegister(name string, rcvr interface{}) error\n}\n```\nIRegisterPlugin represents register plugin.\n\n```go\ntype IServerCodecPlugin interface {\n\tIPreReadRequestHeaderPlugin\n\tIPostReadRequestHeaderPlugin\n\tIPreReadRequestBodyPlugin\n\tIPostReadRequestBodyPlugin\n\tIPreWriteResponsePlugin\n\tIPostWriteResponsePlugin\n}\n```\nIServerCodecPlugin represents .\n\n```go\ntype IServerPluginContainer interface {\n\tAdd(plugin IPlugin) error\n\tRemove(pluginName string) error\n\tGetName(plugin IPlugin) string\n\tGetDescription(plugin IPlugin) string\n\tGetByName(pluginName string) IPlugin\n\tGetAll() []IPlugin\n\n\tDoRegister(name string, rcvr interface{}) error\n\n\tDoPostConnAccept(net.Conn) bool\n\n\tDoPreReadRequestHeader(r *rpc.Request) error\n\tDoPostReadRequestHeader(r *rpc.Request) error\n\n\tDoPreReadRequestBody(body interface{}) error\n\tDoPostReadRequestBody(body interface{}) error\n\n\tDoPreWriteResponse(*rpc.Response, interface{}) error\n\tDoPostWriteResponse(*rpc.Response, interface{}) error\n}\n```\nIServerPluginContainer represents a plugin container that defines all methods to manage plugins. And it also defines all extension points.\n\n```go\nfunc GetPluginContainer() IServerPluginContainer\n```\nGetPluginContainer get PluginContainer of default server.\n\n```go\ntype MultiError struct {\n\tErrors []error\n}\n```\nMultiError holds multiple errors\n\n```go\nfunc NewMultiError(errors []error) *MultiError\n```\nNewMultiError creates and returns an Error with error splice\n\n```go\nfunc (e *MultiError) Error() string\n```\nError returns the message of the actual error\n\n```go\ntype RPCError struct {\n\t// contains filtered or unexported fields\n}\n```\nRPCError holds the error\n\n```go\nfunc NewRPCError(errMsg string) *RPCError\n```\nNewRPCError creates and returns an Error with a message\n\n```go\nfunc (e *RPCError) Error() string\n```\nError returns the message of the actual error\n\n```go\nfunc (e *RPCError) Format(args ...interface{}) error\n```\nFormat returns a formatted new error based on the arguments\n\n```go\nfunc (e *RPCError) Panic()\n```\nPanic output the message and after panics\n\n```go\nfunc (e *RPCError) Panicf(args ...interface{})\n```\nPanicf output the formatted message and after panics\n\n```go\nfunc (e *RPCError) Return() error\n```\nReturn returns the actual error as it is\n\n```go\nfunc (e *RPCError) With(err error) error\n```\nWith does the same thing as Format but it receives an error type which if it's nil it returns a nil error\n\n```go\ntype SelectMode int\n```\nSelectMode defines the algorithm of selecting a services from cluster\n\n```go\nconst (\n\tRandomSelect SelectMode = iota\n\tRoundRobin\n\tLeastActive\n\tConsistentHash\n)\n```\n\n```go\nfunc (s SelectMode) String() string\n```\n\n```go\ntype Server struct {\n\tServerCodecFunc ServerCodecFunc\n\t//PluginContainer must be configured before starting and Register plugins must be configured before invoking RegisterName method\n\tPluginContainer IServerPluginContainer\n\t// contains filtered or unexported fields\n}\n```\nServer represents a RPC Server.\n\n```go\nfunc NewServer() *Server\n```\nNewServer returns a new Server.\n\n```go\nfunc (s *Server) Address() string\n```\nAddress return the listening address.\n\n```go\nfunc (s *Server) Auth(fn AuthorizationFunc) error\n```\nAuth sets authorization function\n\n```go\nfunc (s *Server) Close() error\n```\nClose closes RPC server.\n\n```go\nfunc (s *Server) RegisterName(name string, service interface{})\n```\nRegisterName publishes in the server the set of methods of the receiver value that satisfy the following conditions:\n\n  - exported method of exported type\n  - two arguments, both of exported type\n  - the second argument is a pointer\n  - one return value, of type error\n\nIt returns an error if the receiver is not an exported type or has no suitable methods. It also logs the error using package log. The client accesses each method using a string of the form \"Type.Method\", where Type is the receiver's concrete type.\n\n```go\nfunc (s *Server) Serve(network, address string)\n```\nServe starts and listens RCP requests. It is blocked until receiving connectings from clients.\n\n```go\nfunc (s *Server) ServeByHTTP(ln net.Listener, rpcPath string)\n```\nServeByHTTP starts\n\n```go\nfunc (s *Server) ServeHTTP(w http.ResponseWriter, req *http.Request)\n```\nServeHTTP implements net handler interface\n\n```go\nfunc (s *Server) ServeListener(ln net.Listener)\n```\nServeListener starts\n\n```go\nfunc (s *Server) ServeTLS(network, address string, config *tls.Config)\n```\nServeTLS starts and listens RCP requests. It is blocked until receiving connectings from clients.\n\n```go\nfunc (s *Server) Start(network, address string)\n```\nStart starts and listens RCP requests without blocking.\n\n```go\nfunc (s *Server) StartTLS(network, address string, config *tls.Config)\n```\nStartTLS starts and listens RCP requests without blocking.\n\n```go\ntype ServerCodecFunc func(conn io.ReadWriteCloser) rpc.ServerCodec\n```\nServerCodecFunc is used to create a rpc.ServerCodec from net.Conn.\n\n```go\ntype ServerPluginContainer struct {\n\t// contains filtered or unexported fields\n}\n```\nServerPluginContainer implements IPluginContainer interface.\n\n```go\nfunc (p *ServerPluginContainer) Add(plugin IPlugin) error\n```\nAdd adds a plugin.\n\n```go\nfunc (p *ServerPluginContainer) DoPostConnAccept(conn net.Conn) bool\n```\nDoPostConnAccept handle accepted conn\n\n```go\nfunc (p *ServerPluginContainer) DoPostReadRequestBody(body interface{}) error\n```\nDoPostReadRequestBody invokes DoPostReadRequestBody plugin.\n\n```go\nfunc (p *ServerPluginContainer) DoPostReadRequestHeader(r *rpc.Request) error\n```\nDoPostReadRequestHeader invokes DoPostReadRequestHeader plugin.\n\n```go\nfunc (p *ServerPluginContainer) DoPostWriteResponse(resp *rpc.Response, body interface{}) error\n```\nDoPostWriteResponse invokes DoPostWriteResponse plugin.\n\n```go\nfunc (p *ServerPluginContainer) DoPreReadRequestBody(body interface{}) error\n```\nDoPreReadRequestBody invokes DoPreReadRequestBody plugin.\n\n```go\nfunc (p *ServerPluginContainer) DoPreReadRequestHeader(r *rpc.Request) error\n```\nDoPreReadRequestHeader invokes DoPreReadRequestHeader plugin.\n\n```go\nfunc (p *ServerPluginContainer) DoPreWriteResponse(resp *rpc.Response, body interface{}) error\n```\nDoPreWriteResponse invokes DoPreWriteResponse plugin.\n\n```go\nfunc (p *ServerPluginContainer) DoRegister(name string, rcvr interface{}) error\n```\nDoRegister invokes DoRegister plugin.\n\n```go\nfunc (p *ServerPluginContainer) GetAll() []IPlugin\n```\nGetAll returns all activated plugins\n\n```go\nfunc (p *ServerPluginContainer) GetByName(pluginName string) IPlugin\n```\nGetByName returns a plugin instance by it's name\n\n```go\nfunc (p *ServerPluginContainer) GetDescription(plugin IPlugin) string\n```\nGetDescription returns the name of a plugin, if no GetDescription() implemented it returns an empty string \"\"\n\n```go\nfunc (p *ServerPluginContainer) GetName(plugin IPlugin) string\n```\nGetName returns the name of a plugin, if no GetName() implemented it returns an empty string \"\"\n\n```go\nfunc (p *ServerPluginContainer) Remove(pluginName string) error\n```\nRemove removes a plugin by it's name.\n\n","path":"github.com/LIU-RUI/RPCX","name":"rpcx","synopsis":"","isRedistributable":true}
