Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Handler ¶
type Handler interface {
Handle(context.Context, json.RawMessage) (json.RawMessage, error)
}
Handler implementations will be called by the Router to handle requests made to the associated procedure.
type HandlerFunc ¶
type HandlerFunc func(context.Context, json.RawMessage) (json.RawMessage, error)
The HandlerFunc type is an adapter to allow the use of ordinary functions as Lambda handlers. If f is a function with the appropriate signature, HandlerFunc(f) is a Handler that calls f.
func (HandlerFunc) Handle ¶
func (f HandlerFunc) Handle(ctx context.Context, body json.RawMessage) (json.RawMessage, error)
Handle calls f(ctx, body).
type Option ¶
type Option func(*Router)
Option implementations can mutate the Router to configure how events should be handled.
func MarshalErrorsWith ¶
func MarshalErrorsWith(f func(error) (json.RawMessage, error)) Option
MarshalErrorsWith configures the Router to use the passed function to marshal errors returned from a Handler. This allows streaming additional content which may be included in your error value. If a custom marshaling function isn't provided only the error message will be propagated to the caller. If your marshaling function fails it should return an error; the Router will propagate the original err.Error() in this case.
type Request ¶
type Request struct { Procedure string `json:"procedure"` Body json.RawMessage `json:"body"` }
Request is the expected structure of an event which can be routed. It contains a Procedure field which names the Handler which should handle the request, and the body to be passed to the handler.
type Response ¶
type Response struct { Body json.RawMessage `json:"body,omitempty"` Error json.RawMessage `json:"error,omitempty"` }
Response is returned from the Router.Handle function and is the form of the event which will returned from the lambda invoke function. NOTE: Errors returned from a Handler won't be propagated, instead they're marshaled to json and streamed as part of the response.
type Router ¶
Router exposes a 'Handle' method which should be passed to 'lambda.Start'. It does the work of unwrapping the request event and passing it to the relevant Handler, and wrapping the response, or error returned.