Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrInternalError = &Error{StatusInternalError, "Internal error"} ErrRpcError = &Error{StatusRpcError, "RPC error"} ErrMethodNotFound = &Error{StatusRpcMethodNotFound, "Method not found"} ErrInvalidArgs = &Error{StatusRpcInvalidArgs, "Invalid method arguments"} ErrNoResponse = &Error{StatusRpcNoResponse, "No reponse"} )
View Source
var (
ErrMessageTooLarge = errors.New("rpc: message is too large")
)
Functions ¶
This section is empty.
Types ¶
type ConnHandler ¶
type ConnHandler interface {
HandleConn(ServerConn) RequestHandler
}
ConnHandler handles an incoming connection and returns a request handler.
type MessageReader ¶
type MessageReader struct {
// contains filtered or unexported fields
}
MessageReader reads a delimited stream of messages.
func NewMessageReader ¶
func NewMessageReader(r io.Reader) *MessageReader
func (*MessageReader) Read ¶
func (r *MessageReader) Read() ([]byte, error)
Read reads and returns the next messages.
type MessageWriter ¶
type MessageWriter struct {
// contains filtered or unexported fields
}
MessageWriter writes a delimited stream of messages.
func NewMessageWriter ¶
func NewMessageWriter(w io.Writer) *MessageWriter
func (*MessageWriter) Write ¶
func (w *MessageWriter) Write(p []byte) error
type RequestHandler ¶
type RequestHandler interface {
HandleRequest(<-chan struct{}, *Request, ResponseWriter) error
}
RequestHandler handles a request and writes a response.
type ResponseWriter ¶
type ResponseWriter interface { // Status sets the response status code. Status(Status) // Headers returns mutable response headers or an empty map. Headers() map[string][]byte // Length sets the response body length, 0 means no body, -1 means an unlimited body. Length(int64) // Write flushes the response and writes the body data. Write([]byte) (int, error) // Write messages sets the status to OK, the length to -1 and returns a MessageWriter. ToMessageWriter() *MessageWriter }
type Server ¶
type Server struct { Handler ConnHandler ErrorLog *log.Logger }
func (*Server) ListenAndServe ¶
type ServerConn ¶
type Status ¶
type Status string
const ( StatusOK Status = "ok" // Successful result. StatusError Status = "error" // Error result. StatusInternalError Status = "internal_error" // Internal server error. StatusRpcError Status = "rpc_error" // Generic RPC error. StatusRpcMethodNotFound Status = "rpc_method_not_found" // RPC method is not found. StatusRpcInvalidArgs Status = "rpc_invalid_args" // Invalid method arguments. StatusRpcNoResponse Status = "rpc_no_response" // Handler has not written a response. )
Click to show internal directories.
Click to hide internal directories.