Documentation ¶
Index ¶
- func Start(handler interface{})
- func StartHandler(handler Handler)deprecated
- func StartHandlerFunc[TIn any, TOut any, H HandlerFunc[TIn, TOut]](handler H, options ...Option)
- func StartHandlerWithContext(ctx context.Context, handler Handler)deprecated
- func StartWithContext(ctx context.Context, handler interface{})deprecated
- func StartWithOptions(handler interface{}, options ...Option)
- type Functiondeprecated
- type Handler
- type HandlerFunc
- type Option
- func WithContext(ctx context.Context) Option
- func WithContextValue(key interface{}, value interface{}) Option
- func WithDisallowUnknownFields(disallowUnknownFields bool) Option
- func WithEnableSIGTERM(callbacks ...func()) Option
- func WithSetEscapeHTML(escapeHTML bool) Option
- func WithSetIndent(prefix, indent string) Option
- func WithUseNumber(useNumber bool) Option
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Start ¶
func Start(handler interface{})
Start takes a handler and talks to an internal Lambda endpoint to pass requests to the handler. If the handler does not match one of the supported types an appropriate error message will be returned to the caller. Start blocks, and does not return after being called.
Rules:
- handler must be a function
- handler may take between 0 and two arguments.
- if there are two arguments, the first argument must satisfy the "context.Context" interface.
- handler may return between 0 and two values.
- if there are two return values, the second return value must be an error.
- if there is one return value it must be an error.
Valid function signatures:
func () func (TIn) func () error func (TIn) error func () (TOut, error) func (TIn) (TOut, error) func (context.Context) func (context.Context) error func (context.Context) (TOut, error) func (context.Context, TIn) func (context.Context, TIn) error func (context.Context, TIn) (TOut, error)
Where "TIn" and "TOut" are types compatible with the "encoding/json" standard library. See https://golang.org/pkg/encoding/json/#Unmarshal for how deserialization behaves
"TOut" may also implement the io.Reader interface. If "TOut" is both json serializable and implements io.Reader, then the json serialization is used.
func StartHandler
deprecated
added in
v1.2.0
func StartHandler(handler Handler)
StartHandler takes in a Handler wrapper interface which can be implemented either by a custom function or a struct.
Handler implementation requires a single "Invoke()" function:
func Invoke(context.Context, []byte) ([]byte, error)
Deprecated: use lambda.Start(handler) instead
func StartHandlerFunc ¶ added in v1.36.0
func StartHandlerFunc[TIn any, TOut any, H HandlerFunc[TIn, TOut]](handler H, options ...Option)
StartHandlerFunc is the same as StartWithOptions except that it takes a generic input so that the function signature can be validated at compile time.
func StartHandlerWithContext
deprecated
added in
v1.18.0
StartHandlerWithContext is the same as StartHandler except sets the base context for the function.
Handler implementation requires a single "Invoke()" function:
func Invoke(context.Context, []byte) ([]byte, error)
Deprecated: use lambda.StartWithOptions(handler, lambda.WithContext(ctx)) instead
func StartWithContext
deprecated
added in
v1.18.0
func StartWithOptions ¶ added in v1.32.0
func StartWithOptions(handler interface{}, options ...Option)
StartWithOptions is the same as Start after the application of any handler options specified
Types ¶
type Function
deprecated
type Function struct {
// contains filtered or unexported fields
}
Function struct which wrap the Handler
Deprecated: The Function type is public for the go1.x runtime internal use of the net/rpc package
func NewFunction
deprecated
added in
v1.11.0
func (*Function) Invoke ¶
func (fn *Function) Invoke(req *messages.InvokeRequest, response *messages.InvokeResponse) error
Invoke method try to perform a command given an InvokeRequest and an InvokeResponse
func (*Function) Ping ¶
func (fn *Function) Ping(req *messages.PingRequest, response *messages.PingResponse) error
Ping method which given a PingRequest and a PingResponse parses the PingResponse
type Handler ¶ added in v1.2.0
func NewHandler ¶ added in v1.7.0
func NewHandler(handlerFunc interface{}) Handler
NewHandler creates a base lambda handler from the given handler function. The returned Handler performs JSON serialization and deserialization, and delegates to the input handler function. The handler function parameter must satisfy the rules documented by Start. If handlerFunc is not a valid handler, the returned Handler simply reports the validation error.
func NewHandlerWithOptions ¶ added in v1.32.0
NewHandlerWithOptions creates a base lambda handler from the given handler function. The returned Handler performs JSON serialization and deserialization, and delegates to the input handler function. The handler function parameter must satisfy the rules documented by Start. If handlerFunc is not a valid handler, the returned Handler simply reports the validation error.
type HandlerFunc ¶ added in v1.36.0
HandlerFunc represents a valid input with two arguments and two returns as described by Start
type Option ¶ added in v1.32.0
type Option func(*handlerOptions)
func WithContext ¶ added in v1.32.0
WithContext is a HandlerOption that sets the base context for all invocations of the handler.
Usage:
lambda.StartWithOptions( func (ctx context.Context) (string, error) { return ctx.Value("foo"), nil }, lambda.WithContext(context.WithValue(context.Background(), "foo", "bar")) )
func WithContextValue ¶ added in v1.42.0
func WithContextValue(key interface{}, value interface{}) Option
WithContextValue adds a value to the handler context. If a base context was set using WithContext, that base is used as the parent.
Usage:
lambda.StartWithOptions( func (ctx context.Context) (string, error) { return ctx.Value("foo"), nil }, lambda.WithContextValue("foo", "bar") )
func WithDisallowUnknownFields ¶ added in v1.42.0
WithUseNumber sets the DisallowUnknownFields option on the underlying json decoder
Usage:
lambda.StartWithOptions( func (event any) (any, error) { return event, nil }, lambda.WithDisallowUnknownFields(true) )
func WithEnableSIGTERM ¶ added in v1.34.0
func WithEnableSIGTERM(callbacks ...func()) Option
WithEnableSIGTERM enables SIGTERM behavior within the Lambda platform on container spindown. SIGKILL will occur ~500ms after SIGTERM. Optionally, an array of callback functions to run on SIGTERM may be provided.
Usage:
lambda.StartWithOptions( func (event any) (any, error) { return event, nil }, lambda.WithEnableSIGTERM(func() { log.Print("function container shutting down...") }) )
func WithSetEscapeHTML ¶ added in v1.32.0
WithSetEscapeHTML sets the SetEscapeHTML argument on the underlying json encoder
Usage:
lambda.StartWithOptions( func () (string, error) { return "<html><body>hello!></body></html>", nil }, lambda.WithSetEscapeHTML(true), )
func WithSetIndent ¶ added in v1.32.0
WithSetIndent sets the SetIndent argument on the underling json encoder
Usage:
lambda.StartWithOptions( func (event any) (any, error) { return event, nil }, lambda.WithSetIndent(">"," "), )
func WithUseNumber ¶ added in v1.42.0
WithUseNumber sets the UseNumber option on the underlying json decoder
Usage:
lambda.StartWithOptions( func (event any) (any, error) { return event, nil }, lambda.WithUseNumber(true) )
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package handlertrace allows middleware authors using lambda.NewHandler to instrument request and response events.
|
Package handlertrace allows middleware authors using lambda.NewHandler to instrument request and response events. |