lambda

package
v0.0.0-...-6c0fb1d Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2023 License: Apache-2.0 Imports: 22 Imported by: 0

README

Overview

Go Reference

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func StartHandlerFunc

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.

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

func NewFunction(handler *handlerOptions) *Function

NewFunction which creates a Function with a given Handler

Deprecated: The Function type is public for the go1.x runtime internal use of the net/rpc package

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

type Handler interface {
	Invoke(ctx context.Context, payload []byte) ([]byte, error)
}

type HandlerFunc

type HandlerFunc[TIn, TOut any] interface {
	func(context.Context, TIn) (TOut, error)
}

HandlerFunc represents a valid input with two arguments and two returns as described by Start

type Option

type Option func(*handlerOptions)

func WithContext

func WithContext(ctx context.Context) Option

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 WithEnableSIGTERM

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

func WithSetEscapeHTML(escapeHTML bool) Option

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

func WithSetIndent(prefix, indent string) Option

WithSetIndent sets the SetIndent argument on the underling json encoder

Usage:

lambda.StartWithOptions(
	func (event any) (any, error) {
		return event, nil
	},
	lambda.WithSetIndent(">"," "),
)

Jump to

Keyboard shortcuts

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