Documentation ¶
Index ¶
- Constants
- Variables
- func HTTPRequest2RpcxRequest(r *http.Request) (*protocol.Message, error)
- func RegisterMakeListener(network string, ml MakeListener)
- type MakeListener
- type OptionFn
- type Plugin
- type PluginContainer
- type PostConnAcceptPlugin
- type PostConnClosePlugin
- type PostReadRequestPlugin
- type PostWriteRequestPlugin
- type PostWriteResponsePlugin
- type PreReadRequestPlugin
- type PreWriteRequestPlugin
- type PreWriteResponsePlugin
- type RegisterFunctionPlugin
- type RegisterPlugin
- type Reset
- type Server
- func (s *Server) ActiveClientConn() []net.Conn
- func (s *Server) Address() net.Addr
- func (s *Server) Close() error
- func (s *Server) Register(rcvr interface{}, metadata string) error
- func (s *Server) RegisterFunction(servicePath string, fn interface{}, metadata string) error
- func (s *Server) RegisterFunctionName(servicePath string, name string, fn interface{}, metadata string) error
- func (s *Server) RegisterName(name string, rcvr interface{}, metadata string) error
- func (s *Server) RegisterOnShutdown(f func(s *Server))
- func (s *Server) SendMessage(conn net.Conn, servicePath, serviceMethod string, metadata map[string]string, ...) error
- func (s *Server) Serve(network, address string) (err error)
- func (s *Server) ServeHTTP(w http.ResponseWriter, req *http.Request)
- func (s *Server) Shutdown(ctx context.Context) error
- func (s *Server) UnregisterAll() error
Constants ¶
const ( XVersion = "X-RPCX-Version" XMessageType = "X-RPCX-MesssageType" XHeartbeat = "X-RPCX-Heartbeat" XOneway = "X-RPCX-Oneway" XMessageStatusType = "X-RPCX-MessageStatusType" XSerializeType = "X-RPCX-SerializeType" XMessageID = "X-RPCX-MessageID" XServicePath = "X-RPCX-ServicePath" XServiceMethod = "X-RPCX-ServiceMethod" XMeta = "X-RPCX-Meta" XErrorMessage = "X-RPCX-ErrorMessage" )
const ( // ReaderBuffsize is used for bufio reader. ReaderBuffsize = 1024 // WriterBuffsize is used for bufio writer. WriterBuffsize = 1024 )
Variables ¶
var ( // RemoteConnContextKey is a context key. It can be used in // services with context.WithValue to access the connection arrived on. // The associated value will be of type net.Conn. RemoteConnContextKey = &contextKey{"remote-conn"} // StartRequestContextKey records the start time StartRequestContextKey = &contextKey{"start-parse-request"} // StartSendRequestContextKey records the start time StartSendRequestContextKey = &contextKey{"start-send-request"} )
var ErrServerClosed = errors.New("http: Server closed")
ErrServerClosed is returned by the Server's Serve, ListenAndServe after a call to Shutdown or Close.
var UsePool bool
Functions ¶
func HTTPRequest2RpcxRequest ¶
HTTPRequest2RpcxRequest converts a http request to a rpcx request.
func RegisterMakeListener ¶
func RegisterMakeListener(network string, ml MakeListener)
RegisterMakeListener registers a MakeListener for network.
Types ¶
type MakeListener ¶
MakeListener defines a listener generater.
type OptionFn ¶
type OptionFn func(*Server)
OptionFn configures options of server.
func WithReadTimeout ¶
WithReadTimeout sets readTimeout.
func WithWriteTimeout ¶
WithWriteTimeout sets writeTimeout.
type PluginContainer ¶
type PluginContainer interface { Add(plugin Plugin) Remove(plugin Plugin) All() []Plugin DoRegister(name string, rcvr interface{}, metadata string) error DoRegisterFunction(name string, fn interface{}, metadata string) error DoUnregister(name string) error DoPostConnAccept(net.Conn) (net.Conn, bool) DoPostConnClose(net.Conn) bool DoPreReadRequest(ctx context.Context) error DoPostReadRequest(ctx context.Context, r *protocol.Message, e error) error DoPreWriteResponse(context.Context, *protocol.Message, *protocol.Message) error DoPostWriteResponse(context.Context, *protocol.Message, *protocol.Message, error) error DoPreWriteRequest(ctx context.Context) error DoPostWriteRequest(ctx context.Context, r *protocol.Message, e error) error }
PluginContainer represents a plugin container that defines all methods to manage plugins. And it also defines all extension points.
type PostConnAcceptPlugin ¶
PostConnAcceptPlugin represents connection accept plugin. if returns false, it means subsequent IPostConnAcceptPlugins should not contiune to handle this conn and this conn has been closed.
type PostConnClosePlugin ¶
PostConnClosePlugin represents client connection close plugin.
type PostReadRequestPlugin ¶
type PostReadRequestPlugin interface {
PostReadRequest(ctx context.Context, r *protocol.Message, e error) error
}
PostReadRequestPlugin represents .
type PostWriteRequestPlugin ¶
type PostWriteRequestPlugin interface {
PostWriteRequest(ctx context.Context, r *protocol.Message, e error) error
}
PostWriteRequestPlugin represents .
type PostWriteResponsePlugin ¶
type PostWriteResponsePlugin interface {
PostWriteResponse(context.Context, *protocol.Message, *protocol.Message, error) error
}
PostWriteResponsePlugin represents .
type PreReadRequestPlugin ¶
PreReadRequestPlugin represents .
type PreWriteRequestPlugin ¶
PreWriteRequestPlugin represents .
type PreWriteResponsePlugin ¶
type PreWriteResponsePlugin interface {
PreWriteResponse(context.Context, *protocol.Message, *protocol.Message) error
}
PreWriteResponsePlugin represents .
type RegisterFunctionPlugin ¶
type RegisterFunctionPlugin interface {
RegisterFunction(name string, fn interface{}, metadata string) error
}
RegisterFunctionPlugin is .
type RegisterPlugin ¶
type RegisterPlugin interface { Register(name string, rcvr interface{}, metadata string) error Unregister(name string) error }
RegisterPlugin is .
type Server ¶
type Server struct { Plugins PluginContainer // AuthFunc can be used to auth. AuthFunc func(ctx context.Context, req *protocol.Message, token string) error // contains filtered or unexported fields }
Server is rpcx server that use TCP or UDP.
func (*Server) ActiveClientConn ¶
func (*Server) Register ¶
Register publishes in the server the set of methods of the receiver value that satisfy the following conditions:
- exported method of exported type
- three arguments, the first is of context.Context, both of exported type for three arguments
- the third argument is a pointer
- one return value, of type error
It returns an error if the receiver is not an exported type or has no suitable methods. It also logs the error. The client accesses each method using a string of the form "Type.Method", where Type is the receiver's concrete type.
func (*Server) RegisterFunction ¶
RegisterFunction publishes a function that satisfy the following conditions:
- three arguments, the first is of context.Context, both of exported type for three arguments
- the third argument is a pointer
- one return value, of type error
The client accesses function using a string of the form "servicePath.Method".
func (*Server) RegisterFunctionName ¶
func (s *Server) RegisterFunctionName(servicePath string, name string, fn interface{}, metadata string) error
RegisterFunctionName is like RegisterFunction but uses the provided name for the function instead of the function's concrete type.
func (*Server) RegisterName ¶
RegisterName is like Register but uses the provided name for the type instead of the receiver's concrete type.
func (*Server) RegisterOnShutdown ¶
RegisterOnShutdown registers a function to call on Shutdown. This can be used to gracefully shutdown connections.
func (*Server) SendMessage ¶
func (s *Server) SendMessage(conn net.Conn, servicePath, serviceMethod string, metadata map[string]string, data []byte) error
SendMessage a request to the specified client. The client is designated by the conn. conn can be gotten from context in services:
ctx.Value(RemoteConnContextKey)
servicePath, serviceMethod, metadata can be set to zero values.
func (*Server) Serve ¶
Serve starts and listens RPC requests. It is blocked until receiving connectings from clients.
func (*Server) ServeHTTP ¶
func (s *Server) ServeHTTP(w http.ResponseWriter, req *http.Request)
ServeHTTP implements an http.Handler that answers RPC requests.
func (*Server) Shutdown ¶
Shutdown gracefully shuts down the server without interrupting any active connections. Shutdown works by first closing the listener, then closing all idle connections, and then waiting indefinitely for connections to return to idle and then shut down. If the provided context expires before the shutdown is complete, Shutdown returns the context's error, otherwise it returns any error returned from closing the Server's underlying Listener.
func (*Server) UnregisterAll ¶
UnregisterAll unregisters all services. You can call this method when you want to shutdown/upgrade this node.