Documentation
¶
Index ¶
- func Error(code ErrCode, text string) error
- func Errorf(code ErrCode, format string, args ...interface{}) error
- func ResponseError(resp Response) error
- type CallInfo
- type Caller
- type Client
- type ErrCode
- type Handler
- type MethodSpec
- type Registry
- type Request
- type RequestHeaders
- type Response
- type Server
- type ServerInterceptor
- type ServerOption
- type ServiceSpec
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Error ¶
Error returns an error with the given code and error text. If code is OK, nil will be returned.
func Errorf ¶
Errorf returns an error with the given code and the formatted error text. If code is OK, nil will be returned.
func ResponseError ¶
ResponseError returns the error for the given response.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is mrpc client to call service methods. A client is transport independent.
func NewClient ¶
func NewClient(rw io.ReadWriter) *Client
NewClient creates a new mrpc client. When calling a method with Call, the request will be written to the writing part and the response will be read from the reading part of rw.
type ErrCode ¶
type ErrCode int
ErrCode is an enumeration of supported error codes.
const ( OK ErrCode = 0 Unknown ErrCode = 1 Timeout ErrCode = 2 NotFound ErrCode = 3 AlreadyExists ErrCode = 4 InvalidArgument ErrCode = 5 Forbidden ErrCode = 7 Internal ErrCode = 8 )
Enumerators for ErrCode.
func (*ErrCode) DecodeMsgpack ¶
DecodeMsgpack implements the Decoder interface for ErrCode.
type Handler ¶
Handler is a function type for mrpc handlers. A handler is called for each request and basically defines a service's method.
type MethodSpec ¶
MethodSpec holds the data for a single method. A method has a unique id within the defined service and a handler which completes all incoming requests.
type Registry ¶
type Registry interface {
Register(svc ServiceSpec)
}
Registry defines an interface for registering a service specification.
type Request ¶
type Request struct {
Service string
Method int
Headers RequestHeaders
Body []byte
}
Request holds the data for a single mrpc request. The target service is specified by its name and must be registered at the corresponding mrpc server. A service contains methods, each identified by an ordinal. With this ordinal the method of the targeted service is specified.
func (*Request) DecodeMsgpack ¶
DecodeMsgpack implements the Decoder interface for Request.
type RequestHeaders ¶
type RequestHeaders struct {
Timeout uint64
}
RequestHeaders holds all supported header data for a mrpc request.
func (*RequestHeaders) DecodeMsgpack ¶
func (o *RequestHeaders) DecodeMsgpack(r *msgpack.Reader) error
DecodeMsgpack implements the Decoder interface for RequestHeaders.
func (*RequestHeaders) EncodeMsgpack ¶
func (o *RequestHeaders) EncodeMsgpack(w *msgpack.Writer) (err error)
EncodeMsgpack implements the Encoder interface for RequestHeaders.
type Response ¶
Response holds the data for an mrpc response. If ErrCode is not OK, an error with the specified error text will be reported to the client. In this case the return value will be ignored. In case of a successful call, the return value will be reported to the client.
func ErrorResponse ¶
ErrorResponse returns a response which indicates the given error.
func ErrorResponsef ¶
func (*Response) DecodeMsgpack ¶
DecodeMsgpack implements the Decoder interface for Response.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server is a mrpc server, where services can be registered. A server is transport independent and the network layer has to be implemented separately.
func NewServer ¶
func NewServer(o ...ServerOption) (*Server, error)
NewServer creates a new mrpc server with the given options.
func (*Server) Execute ¶
Execute executes a single request and calls the corresponding method. If the requested service or method was not registered, an error response will be returned.
func (*Server) Register ¶
func (s *Server) Register(svc ServiceSpec)
Register registers a service to the server. If an invalid service specification is passed or a service with the same id was already registered, the function will panic.
type ServerInterceptor ¶
ServerInterceptor defines a function type for intercepting a request on the server side. The interceptor is responsible to call h to complete the method call.
type ServerOption ¶
type ServerOption func(*serverOptions) error
ServerOption represents an option which can be used to configure an mrpc server.
func WithServerInterceptor ¶
func WithServerInterceptor(interceptor ServerInterceptor) ServerOption
WithServerInterceptor adds an interceptor for method calls on the server side. It is possible to add multiple interceptors. In thas case they are executed in the order they are provided.
type ServiceSpec ¶
type ServiceSpec struct {
Name string
Service interface{}
Methods []MethodSpec
}
ServiceSpec holds the data for a service. A service has a unique name and holds the specification for all containing methods.