Documentation ¶
Overview ¶
Package gorpc provides simple RPC API for highload projects.
Gorpc has the following features:
- Easy-to-use API.
- Optimized for high load (>10K qps).
- Uses as low network bandwidth as possible.
- Minimizes the number of TCP connections in TIME_WAIT and WAIT_CLOSE states.
- Minimizes the number of send() and recv() syscalls.
- Provides ability to use arbitrary underlying transport. By default TCP is used, but TLS and UNIX sockets are already available.
Index ¶
- Constants
- Variables
- func NilErrorLogger(format string, args ...interface{})
- func SetErrorLogger(f LoggerFunc)
- type AsyncResult
- type Client
- func (c *Client) Call(request Request) (Response, error)
- func (c *Client) CallAsync(request Request) (*AsyncResult, error)
- func (c *Client) CallTimeout(request Request, timeout time.Duration) (Response, error)
- func (c *Client) PendingRequestsCount() int
- func (c *Client) Start()
- func (c *Client) Stop()
- type ClientError
- type ConnStats
- type Context
- func (c *Context) Abort()
- func (c *Context) AddCookie(cook *Cookie)
- func (c *Context) Body() []byte
- func (c *Context) Cookie(key string) string
- func (c *Context) Data(code int, contenttype string, data []byte)
- func (c *Context) DelHeader(key string)
- func (c *Context) GetString(key string) string
- func (c *Context) HTML(code int, html []byte)
- func (c *Context) Header(key string) []byte
- func (c *Context) Host() string
- func (c *Context) JSON(code int, v interface{})
- func (c *Context) Method() string
- func (c *Context) Params(name string) string
- func (c *Context) Path() string
- func (c *Context) PostForm(name string) string
- func (c *Context) Query(name string) string
- func (c *Context) RawQuery() map[string]string
- func (c *Context) Redirect(req *Request)
- func (c *Context) Referer() string
- func (c *Context) RemoteAddr() string
- func (c *Context) SetHeader(key string, val []byte)
- func (c *Context) SetString(key, val string)
- func (c *Context) Status(statuscode int)
- func (c *Context) String(code int, str string)
- func (c *Context) Uri() string
- func (c *Context) UserAgent() []byte
- func (c *Context) Version() string
- func (c *Context) VisitHeader(f func(key string, val []byte))
- type Cookie
- func (*Cookie) Descriptor() ([]byte, []int)
- func (m *Cookie) GetDomain() string
- func (m *Cookie) GetExpiredSec() int64
- func (m *Cookie) GetHttpOnly() bool
- func (m *Cookie) GetName() string
- func (m *Cookie) GetPath() string
- func (m *Cookie) GetSecure() bool
- func (m *Cookie) GetValue() []byte
- func (*Cookie) ProtoMessage()
- func (m *Cookie) Reset()
- func (m *Cookie) String() string
- func (m *Cookie) XXX_DiscardUnknown()
- func (m *Cookie) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
- func (m *Cookie) XXX_Merge(src proto.Message)
- func (m *Cookie) XXX_Size() int
- func (m *Cookie) XXX_Unmarshal(b []byte) error
- type DialFunc
- type H
- type Handle
- type Handler
- type HandlerFunc
- type Listener
- type LoggerFunc
- type OnConnectFunc
- type Params
- type Request
- func (*Request) Descriptor() ([]byte, []int)
- func (m *Request) GetBody() []byte
- func (m *Request) GetCookie() map[string][]byte
- func (m *Request) GetForm() map[string]string
- func (m *Request) GetForm1() map[string][]byte
- func (m *Request) GetHeader() map[string][]byte
- func (m *Request) GetHost() string
- func (m *Request) GetId() uint64
- func (m *Request) GetMethod() string
- func (m *Request) GetPath() string
- func (m *Request) GetQuery() map[string]string
- func (m *Request) GetQuery1() map[string][]byte
- func (m *Request) GetReceived() int64
- func (m *Request) GetReferer() string
- func (m *Request) GetRemoteAddr() string
- func (m *Request) GetUri() []byte
- func (m *Request) GetUserAgent() []byte
- func (m *Request) GetVersion() string
- func (*Request) ProtoMessage()
- func (m *Request) Reset()
- func (m *Request) String() string
- func (m *Request) XXX_DiscardUnknown()
- func (m *Request) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
- func (m *Request) XXX_Merge(src proto.Message)
- func (m *Request) XXX_Size() int
- func (m *Request) XXX_Unmarshal(b []byte) error
- type Response
- func (*Response) Descriptor() ([]byte, []int)
- func (m *Response) GetBody() []byte
- func (m *Response) GetCookies() []*Cookie
- func (m *Response) GetHeader() map[string][]byte
- func (m *Response) GetId() uint64
- func (m *Response) GetRedirectRequest() *Request
- func (m *Response) GetStatusCode() int32
- func (m *Response) GetVersion() string
- func (*Response) ProtoMessage()
- func (m *Response) Reset()
- func (m *Response) String() string
- func (m *Response) XXX_DiscardUnknown()
- func (m *Response) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
- func (m *Response) XXX_Merge(src proto.Message)
- func (m *Response) XXX_Size() int
- func (m *Response) XXX_Unmarshal(b []byte) error
- type ReverseProxy
- type Router
- func (me *Router) Any(path string, handles ...Handler)
- func (me *Router) DEL(path string, handles ...Handler)
- func (me *Router) GET(path string, handles ...Handler)
- func (me *Router) Handle(req Request) (res Response)
- func (me *Router) NoRoute(handlers ...Handler)
- func (me *Router) POST(path string, handles ...Handler)
- func (me *Router) Run()
- func (me *Router) Stop()
- type Server
- type StatusResponse
- func (*StatusResponse) Descriptor() ([]byte, []int)
- func (m *StatusResponse) GetDomains() []string
- func (m *StatusResponse) GetPaths() []string
- func (*StatusResponse) ProtoMessage()
- func (m *StatusResponse) Reset()
- func (m *StatusResponse) String() string
- func (m *StatusResponse) XXX_DiscardUnknown()
- func (m *StatusResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
- func (m *StatusResponse) XXX_Merge(src proto.Message)
- func (m *StatusResponse) XXX_Size() int
- func (m *StatusResponse) XXX_Unmarshal(b []byte) error
Constants ¶
const ( // DefaultConcurrency is the default number of concurrent rpc calls // the server can process. DefaultConcurrency = 8 * 1024 // DefaultRequestTimeout is the default timeout for client request. DefaultRequestTimeout = 20 * time.Second // DefaultPendingMessages is the default number of pending messages // handled by Client and Server. DefaultPendingMessages = 32 * 1024 // DefaultFlushDelay is the default delay between message flushes // on Client and Server. DefaultFlushDelay = -1 // DefaultBufferSize is the default size for Client and Server buffers. DefaultBufferSize = 64 * 1024 )
Variables ¶
var APPJSON = []byte("application/json")
var ErrCanceled = &ClientError{ Canceled: true, err: fmt.Errorf("the call has been canceled"), }
ErrCanceled may be returned from rpc call if AsyncResult.Cancel has been called.
var JAVASCRIPT = []byte("text/javascript")
var STATUS = []byte("_status")
var TEXTHTML = []byte("text/html")
var TEXTPLAIN = []byte("text/plain")
Functions ¶
func NilErrorLogger ¶
func NilErrorLogger(format string, args ...interface{})
NilErrorLogger discards all error messages.
Pass NilErrorLogger to SetErrorLogger() in order to suppress error log generated by gorpc.
func SetErrorLogger ¶
func SetErrorLogger(f LoggerFunc)
SetErrorLogger sets the given error logger to use in gorpc.
By default log.Printf is used for error logging.
Types ¶
type AsyncResult ¶
type AsyncResult struct { // The response can be read only after <-Done unblocks. Response Response // The error can be read only after <-Done unblocks. // The error can be casted to ClientError. Error error // Response and Error become available after <-Done unblocks. Done <-chan struct{} // contains filtered or unexported fields }
AsyncResult is a result returned from Client.CallAsync().
func (*AsyncResult) Cancel ¶
func (m *AsyncResult) Cancel()
Cancel cancels async call.
Canceled call isn't sent to the server unless it is already sent there. Canceled call may successfully complete if it has been already sent to the server before Cancel call.
It is safe calling this function multiple times from concurrently running goroutines.
type Client ¶
type Client struct { // Server address to connect to. // // The address format depends on the underlying transport provided // by Client.Dial. The following transports are provided out of the box: // * TCP - see NewTCPClient() and NewTCPServer(). // * TLS - see NewTLSClient() and NewTLSServer(). // * Unix sockets - see NewUnixClient() and NewUnixServer(). // // By default TCP transport is used. Addr string // The number of concurrent connections the client should establish // to the sever. // By default only one connection is established. Conns int // The maximum number of pending requests in the queue. // // The number of pending requsts should exceed the expected number // of concurrent goroutines calling client's methods. // Otherwise a lot of ClientError.Overflow errors may appear. // // Default is DefaultPendingMessages. PendingRequests int // Delay between request flushes. // // Negative values lead to immediate requests' sending to the server // without their buffering. This minimizes rpc latency at the cost // of higher CPU and network usage. // // Default value is DefaultFlushDelay. FlushDelay time.Duration // Maximum request time. // Default value is DefaultRequestTimeout. RequestTimeout time.Duration // Size of send buffer per each underlying connection in bytes. // Default value is DefaultBufferSize. SendBufferSize int // Size of recv buffer per each underlying connection in bytes. // Default value is DefaultBufferSize. RecvBufferSize int // OnConnect is called whenever connection to server is established. // The callback can be used for authentication/authorization/encryption // and/or for custom transport wrapping. // // See also Dial callback, which can be used for sophisticated // transport implementation. OnConnect OnConnectFunc // The client calls this callback when it needs new connection // to the server. // The client passes Client.Addr into Dial(). // // Override this callback if you want custom underlying transport // and/or authentication/authorization. // Don't forget overriding Server.Listener accordingly. // // See also OnConnect for authentication/authorization purposes. // // * NewTLSClient() and NewTLSServer() can be used for encrypted rpc. // * NewUnixClient() and NewUnixServer() can be used for fast local // inter-process rpc. // // By default it returns TCP connections established to the Client.Addr. Dial DialFunc // LogError is used for error logging. // // By default the function set via SetErrorLogger() is used. LogError LoggerFunc // Connection statistics. // // The stats doesn't reset automatically. Feel free resetting it // any time you wish. Stats ConnStats IsStopped bool // contains filtered or unexported fields }
Client implements RPC client.
The client must be started with Client.Start() before use.
It is absolutely safe and encouraged using a single client across arbitrary number of concurrently running goroutines.
Default client settings are optimized for high load, so don't override them without valid reason.
func NewTCPClient ¶
NewTCPClient creates a client connecting over TCP to the server listening to the given addr.
The returned client must be started after optional settings' adjustment.
The corresponding server must be created with NewTCPServer().
func NewTLSClient ¶
NewTLSClient creates a client connecting over TLS (aka SSL) to the server listening to the given addr using the given TLS config.
The returned client must be started after optional settings' adjustment.
The corresponding server must be created with NewTLSServer().
func NewUnixClient ¶
NewUnixClient creates a client connecting over unix socket to the server listening to the given addr.
The returned client must be started after optional settings' adjustment.
The corresponding server must be created with NewUnixServer().
func (*Client) Call ¶
Call sends the given request to the server and obtains response from the server. Returns non-nil error if the response cannot be obtained during Client.RequestTimeout or server connection problems occur. The returned error can be casted to ClientError.
Request and response types may be arbitrary. All the request and response types the client may use must be registered via RegisterType() before starting the client. There is no need in registering base Go types such as int, string, bool, float64, etc. or arrays, slices and maps containing base Go types.
Hint: use Dispatcher for distinct calls' construction.
Don't forget starting the client with Client.Start() before calling Client.Call().
func (*Client) CallAsync ¶
func (c *Client) CallAsync(request Request) (*AsyncResult, error)
CallAsync starts async rpc call.
Rpc call is complete after <-AsyncResult.Done unblocks. If you want canceling the request, just throw away the returned AsyncResult.
CallAsync doesn't respect Client.RequestTimeout - response timeout may be controlled by the caller via something like:
r := c.CallAsync("foobar") select { case <-time.After(c.RequestTimeout): log.Printf("rpc timeout!") case <-r.Done: processResponse(r.Response, r.Error) }
Request and response types may be arbitrary. All the request and response types the client may use must be registered via RegisterType() before starting the client. There is no need in registering base Go types such as int, string, bool, float64, etc. or arrays, slices and maps containing base Go types.
Don't forget starting the client with Client.Start() before calling Client.CallAsync().
func (*Client) CallTimeout ¶
CallTimeout sends the given request to the server and obtains response from the server. Returns non-nil error if the response cannot be obtained during the given timeout or server connection problems occur. The returned error can be casted to ClientError.
Request and response types may be arbitrary. All the request and response types the client may use must be registered via RegisterType() before starting the client. There is no need in registering base Go types such as int, string, bool, float64, etc. or arrays, slices and maps containing base Go types.
Hint: use Dispatcher for distinct calls' construction.
Don't forget starting the client with Client.Start() before calling Client.Call().
func (*Client) PendingRequestsCount ¶
PendingRequestsCount returns the instant number of pending requests.
The main purpose of this function is to use in load-balancing schemes where load should be balanced between multiple rpc clients.
Don't forget starting the client with Client.Start() before calling this function.
func (*Client) Start ¶
func (c *Client) Start()
Start starts rpc client. Establishes connection to the server on Client.Addr.
All the request and response types the client may use must be registered via RegisterType() before starting the client. There is no need in registering base Go types such as int, string, bool, float64, etc. or arrays, slices and maps containing base Go types.
type ClientError ¶
type ClientError struct { // Set if the error is timeout-related. Timeout bool // Set if the error is connection-related. Connection bool // Set if the error is server-related. Server bool // Set if the error is related to internal resources' overflow. // Increase PendingRequests if you see a lot of such errors. Overflow bool // May be set if AsyncResult.Cancel is called. Canceled bool // contains filtered or unexported fields }
ClientError is an error Client methods can return.
func (*ClientError) Error ¶
func (e *ClientError) Error() string
type ConnStats ¶
type ConnStats struct { // The number of rpc calls performed. RPCCalls uint64 // The total aggregate time for all rpc calls in milliseconds. // // This time can be used for calculating the average response time // per RPC: // avgRPCTtime = RPCTime / RPCCalls RPCTime uint64 // The number of bytes written to the underlying connections. BytesWritten uint64 // The number of bytes read from the underlying connections. BytesRead uint64 // The number of Read() calls. ReadCalls uint64 // The number of Read() errors. ReadErrors uint64 // The number of Write() calls. WriteCalls uint64 // The number of Write() errors. WriteErrors uint64 // The number of Dial() calls. DialCalls uint64 // The number of Dial() errors. DialErrors uint64 // The number of Accept() calls. AcceptCalls uint64 // The number of Accept() errors. AcceptErrors uint64 // contains filtered or unexported fields }
ConnStats provides connection statistics. Applied to both gorpc.Client and gorpc.Server.
Use stats returned from ConnStats.Snapshot() on live Client and / or Server, since the original stats can be updated by concurrently running goroutines.
func (*ConnStats) AvgRPCBytes ¶
AvgRPCBytes returns the average bytes sent / received per RPC.
Use stats returned from ConnStats.Snapshot() on live Client and / or Server, since the original stats can be updated by concurrently running goroutines.
func (*ConnStats) AvgRPCCalls ¶
AvgRPCCalls returns the average number of write() / read() syscalls per PRC.
Use stats returned from ConnStats.Snapshot() on live Client and / or Server, since the original stats can be updated by concurrently running goroutines.
func (*ConnStats) AvgRPCTime ¶
AvgRPCTime returns the average RPC execution time.
Use stats returned from ConnStats.Snapshot() on live Client and / or Server, since the original stats can be updated by concurrently running goroutines.
type Context ¶
type Context struct {
// contains filtered or unexported fields
}
func (*Context) RemoteAddr ¶
func (*Context) VisitHeader ¶
type Cookie ¶
type Cookie struct { Name string `protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty"` Value []byte `protobuf:"bytes,3,opt,name=value,proto3" json:"value,omitempty"` Path string `protobuf:"bytes,4,opt,name=path,proto3" json:"path,omitempty"` Domain string `protobuf:"bytes,5,opt,name=domain,proto3" json:"domain,omitempty"` ExpiredSec int64 `protobuf:"varint,6,opt,name=expired_sec,json=expiredSec,proto3" json:"expired_sec,omitempty"` Secure bool `protobuf:"varint,8,opt,name=secure,proto3" json:"secure,omitempty"` HttpOnly bool `protobuf:"varint,9,opt,name=http_only,json=httpOnly,proto3" json:"http_only,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` }
func (*Cookie) Descriptor ¶
func (*Cookie) GetExpiredSec ¶
func (*Cookie) GetHttpOnly ¶
func (*Cookie) ProtoMessage ¶
func (*Cookie) ProtoMessage()
func (*Cookie) XXX_DiscardUnknown ¶
func (m *Cookie) XXX_DiscardUnknown()
func (*Cookie) XXX_Marshal ¶
func (*Cookie) XXX_Unmarshal ¶
type DialFunc ¶
type DialFunc func(addr string) (conn io.ReadWriteCloser, err error)
DialFunc is a function intended for setting to Client.Dial.
It is expected that the returned conn immediately sends all the data passed via Write() to the server. Otherwise gorpc may hang. The conn implementation must call Flush() on underlying buffered streams before returning from Write().
type Handle ¶
type Handle struct {
// contains filtered or unexported fields
}
handle holds a reference to slice of worker
type HandlerFunc ¶
HandlerFunc is a server handler function.
clientAddr contains client address returned by Listener.Accept(). Request and response types may be arbitrary. All the request and response types the HandlerFunc may use must be registered with RegisterType() before starting the server. There is no need in registering base Go types such as int, string, bool, float64, etc. or arrays, slices and maps containing base Go types.
Hint: use Dispatcher for HandlerFunc construction.
type Listener ¶
type Listener interface { // Init is called on server start. // // addr contains the address set at Server.Addr. Init(addr string) error // Accept must return incoming connections from clients. // clientAddr must contain client's address in user-readable view. // // It is expected that the returned conn immediately // sends all the data passed via Write() to the client. // Otherwise gorpc may hang. // The conn implementation must call Flush() on underlying buffered // streams before returning from Write(). Accept() (conn io.ReadWriteCloser, clientAddr string, err error) // Close closes the listener. // All pending calls to Accept() must immediately return errors after // Close is called. // All subsequent calls to Accept() must immediately return error. Close() error // Addr returns the listener's network address. ListenAddr() net.Addr }
Listener is an interface for custom listeners intended for the Server.
type LoggerFunc ¶
type LoggerFunc func(format string, args ...interface{})
LoggerFunc is an error logging function to pass to gorpc.SetErrorLogger().
type OnConnectFunc ¶
type OnConnectFunc func(remoteAddr string, rwc io.ReadWriteCloser) (io.ReadWriteCloser, error)
OnConnectFunc is a callback, which may be called by both Client and Server on every connection creation if assigned to Client.OnConnect / Server.OnConnect.
remoteAddr is the address of the remote end for the established connection rwc.
The callback must return either rwc itself or a rwc wrapper. The returned connection wrapper MUST send all the data to the underlying rwc on every Write() call, otherwise the connection will hang forever.
The callback may be used for authentication/authorization and/or custom transport wrapping.
type Request ¶
type Request struct { Version string `protobuf:"bytes,2,opt,name=version,proto3" json:"version,omitempty"` Id uint64 `protobuf:"varint,3,opt,name=id,proto3" json:"id,omitempty"` Uri []byte `protobuf:"bytes,4,opt,name=uri,proto3" json:"uri,omitempty"` Method string `protobuf:"bytes,5,opt,name=method,proto3" json:"method,omitempty"` Body []byte `protobuf:"bytes,6,opt,name=body,proto3" json:"body,omitempty"` UserAgent []byte `protobuf:"bytes,8,opt,name=user_agent,json=userAgent,proto3" json:"user_agent,omitempty"` Cookie map[string][]byte `` /* 153-byte string literal not displayed */ Header map[string][]byte `` /* 154-byte string literal not displayed */ RemoteAddr string `protobuf:"bytes,11,opt,name=remote_addr,json=remoteAddr,proto3" json:"remote_addr,omitempty"` Referer string `protobuf:"bytes,12,opt,name=referer,proto3" json:"referer,omitempty"` Received int64 `protobuf:"varint,15,opt,name=received,proto3" json:"received,omitempty"` Path string `protobuf:"bytes,16,opt,name=path,proto3" json:"path,omitempty"` Host string `protobuf:"bytes,17,opt,name=host,proto3" json:"host,omitempty"` Form1 map[string][]byte `` /* 152-byte string literal not displayed */ Query1 map[string][]byte `` /* 154-byte string literal not displayed */ Form map[string]string `` /* 150-byte string literal not displayed */ Query map[string]string `` /* 152-byte string literal not displayed */ XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` }
func (*Request) Descriptor ¶
func (*Request) GetReceived ¶
func (*Request) GetReferer ¶
func (*Request) GetRemoteAddr ¶
func (*Request) GetUserAgent ¶
func (*Request) GetVersion ¶
func (*Request) ProtoMessage ¶
func (*Request) ProtoMessage()
func (*Request) XXX_DiscardUnknown ¶
func (m *Request) XXX_DiscardUnknown()
func (*Request) XXX_Marshal ¶
func (*Request) XXX_Unmarshal ¶
type Response ¶
type Response struct { Version string `protobuf:"bytes,2,opt,name=version,proto3" json:"version,omitempty"` Id uint64 `protobuf:"varint,3,opt,name=id,proto3" json:"id,omitempty"` StatusCode int32 `protobuf:"varint,4,opt,name=status_code,json=statusCode,proto3" json:"status_code,omitempty"` Body []byte `protobuf:"bytes,5,opt,name=body,proto3" json:"body,omitempty"` Header map[string][]byte `` /* 154-byte string literal not displayed */ Cookies []*Cookie `protobuf:"bytes,12,rep,name=cookies,proto3" json:"cookies,omitempty"` RedirectRequest *Request `protobuf:"bytes,13,opt,name=redirect_request,json=redirectRequest,proto3" json:"redirect_request,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` }
func (*Response) Descriptor ¶
func (*Response) GetCookies ¶
func (*Response) GetRedirectRequest ¶
func (*Response) GetStatusCode ¶
func (*Response) GetVersion ¶
func (*Response) ProtoMessage ¶
func (*Response) ProtoMessage()
func (*Response) XXX_DiscardUnknown ¶
func (m *Response) XXX_DiscardUnknown()
func (*Response) XXX_Marshal ¶
func (*Response) XXX_Unmarshal ¶
type ReverseProxy ¶
type ReverseProxy struct { // Log is used for error logging. // By default the function set via SetErrorLogger() is used. Log LoggerFunc // contains filtered or unexported fields }
ReverseProxy proxied HTTP requests to its behine-NAT workers
func NewReverseProxy ¶
func NewReverseProxy() *ReverseProxy
NewReverseProxy setups a new ReverseProxy server The configuration in /etc/gorpc.json will be loaded After this, user can start the server by calling Serve().
func (*ReverseProxy) Serve ¶
func (me *ReverseProxy) Serve(rpc_addr, http_addr string)
Serve starts reverse proxy server and http server and blocks forever
type Router ¶
type Router struct {
// contains filtered or unexported fields
}
Router used by a reverse worker to bind handler to path
type Server ¶
type Server struct { // Address to listen to for incoming connections. // // The address format depends on the underlying transport provided // by Server.Listener. The following transports are provided // out of the box: // * TCP - see NewTCPServer() and NewTCPClient(). // * TLS (aka SSL) - see NewTLSServer() and NewTLSClient(). // * Unix sockets - see NewUnixServer() and NewUnixClient(). // // By default TCP transport is used. Addr string // Handler function for incoming requests. // // Server calls this function for each incoming request. // The function must process the request and return the corresponding response. // // Hint: use Dispatcher for HandlerFunc construction. Handler HandlerFunc // The maximum number of concurrent rpc calls the server may perform. // Default is DefaultConcurrency. Concurrency int // The maximum delay between response flushes to clients. // // Negative values lead to immediate requests' sending to the client // without their buffering. This minimizes rpc latency at the cost // of higher CPU and network usage. // // Default is DefaultFlushDelay. FlushDelay time.Duration // The maximum number of pending responses in the queue. // Default is DefaultPendingMessages. PendingResponses int // Size of send buffer per each underlying connection in bytes. // Default is DefaultBufferSize. SendBufferSize int // Size of recv buffer per each underlying connection in bytes. // Default is DefaultBufferSize. RecvBufferSize int // OnConnect is called whenever connection from client is accepted. // The callback can be used for authentication/authorization/encryption // and/or for custom transport wrapping. // // See also Listener, which can be used for sophisticated transport // implementation. OnConnect OnConnectFunc // The server obtains new client connections via Listener.Accept(). // // Override the listener if you want custom underlying transport // and/or client authentication/authorization. // Don't forget overriding Client.Dial() callback accordingly. // // See also OnConnect for authentication/authorization purposes. // // * NewTLSClient() and NewTLSServer() can be used for encrypted rpc. // * NewUnixClient() and NewUnixServer() can be used for fast local // inter-process rpc. // // By default it returns TCP connections accepted from Server.Addr. Listener Listener // LogError is used for error logging. // // By default the function set via SetErrorLogger() is used. LogError LoggerFunc // Connection statistics. // // The stats doesn't reset automatically. Feel free resetting it // any time you wish. Stats ConnStats // contains filtered or unexported fields }
Server implements RPC server.
Default server settings are optimized for high load, so don't override them without valid reason.
func NewTCPServer ¶
func NewTCPServer(addr string, handler HandlerFunc) *Server
NewTCPServer creates a server listening for TCP connections on the given addr and processing incoming requests with the given HandlerFunc.
The returned server must be started after optional settings' adjustment.
The corresponding client must be created with NewTCPClient().
func NewTLSServer ¶
func NewTLSServer(addr string, handler HandlerFunc, cfg *tls.Config) *Server
NewTLSServer creates a server listening for TLS (aka SSL) connections on the given addr and processing incoming requests with the given HandlerFunc. cfg must contain TLS settings for the server.
The returned server must be started after optional settings' adjustment.
The corresponding client must be created with NewTLSClient().
func NewUnixServer ¶
func NewUnixServer(addr string, handler HandlerFunc) *Server
NewUnixServer creates a server listening for unix connections on the given addr and processing incoming requests with the given HandlerFunc.
The returned server must be started after optional settings' adjustment.
The corresponding client must be created with NewUnixClient().
func (*Server) Start ¶
Start starts rpc server.
All the request and response types the Handler may use must be registered with RegisterType() before starting the server. There is no need in registering base Go types such as int, string, bool, float64, etc. or arrays, slices and maps containing base Go types.
type StatusResponse ¶
type StatusResponse struct { Domains []string `protobuf:"bytes,4,rep,name=domains,proto3" json:"domains,omitempty"` Paths []string `protobuf:"bytes,5,rep,name=paths,proto3" json:"paths,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` }
func (*StatusResponse) Descriptor ¶
func (*StatusResponse) Descriptor() ([]byte, []int)
func (*StatusResponse) GetDomains ¶
func (m *StatusResponse) GetDomains() []string
func (*StatusResponse) GetPaths ¶
func (m *StatusResponse) GetPaths() []string
func (*StatusResponse) ProtoMessage ¶
func (*StatusResponse) ProtoMessage()
func (*StatusResponse) Reset ¶
func (m *StatusResponse) Reset()
func (*StatusResponse) String ¶
func (m *StatusResponse) String() string
func (*StatusResponse) XXX_DiscardUnknown ¶
func (m *StatusResponse) XXX_DiscardUnknown()
func (*StatusResponse) XXX_Marshal ¶
func (m *StatusResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
func (*StatusResponse) XXX_Merge ¶
func (m *StatusResponse) XXX_Merge(src proto.Message)
func (*StatusResponse) XXX_Size ¶
func (m *StatusResponse) XXX_Size() int
func (*StatusResponse) XXX_Unmarshal ¶
func (m *StatusResponse) XXX_Unmarshal(b []byte) error