rpc

package
v0.0.0-...-1c63888 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 30, 2016 License: Apache-2.0 Imports: 10 Imported by: 0

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 Error

type Error struct {
	Status Status
	Text   string
}

func (*Error) Error

func (e *Error) Error() string

type Frame

type Frame struct {
	MethodStatus string
	Headers      map[string][]byte
	BodyLen      int64
	Body         io.Reader
}

frame is a unified Request/Response frame.

func (*Frame) Read

func (f *Frame) Read(r io.Reader) error

Read reads a frame and its body.

func (Frame) Write

func (f Frame) Write(w io.Writer) error

Write writes a frame, but does not write a body.

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.

func (*MessageReader) Reader

func (r *MessageReader) Reader() (length int, reader io.Reader, err error)

Readers returns the next message reader.

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

func (*MessageWriter) Writer

func (w *MessageWriter) Writer(length int) (io.Writer, error)

type Request

type Request struct {
	Method    string
	Length    int64             // Body length.
	Headers   map[string][]byte // Headers or an empty map.
	Body      io.Reader         // Body or an empty reader (server only).
	Cancelled <-chan struct{}   // Closed if the request is cancelled (server only).
}

type RequestHandler

type RequestHandler interface {
	HandleRequest(<-chan struct{}, *Request, ResponseWriter) error
}

RequestHandler handles a request and writes a response.

type Response

type Response struct {
	Status Status
	Length int64     // Body length.
	Body   io.Reader // Body or an empty reader (client only).
}

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

func (s *Server) ListenAndServe(addr string) error

func (*Server) Serve

func (s *Server) Serve(listener net.Listener) error

type ServerConn

type ServerConn interface {
	// Conn returns the underlying connection.
	Conn() mux.Conn

	// Close closes the server connection.
	Close() error

	// Closed returns a channel which is closed when the connection is closed.
	Closed() <-chan struct{}
}

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.
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL