lambdaz

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2022 License: MIT Imports: 17 Imported by: 1

Documentation

Index

Constants

View Source
const (
	ErrIDBadRequest   = errorz.ID("bad-request")
	ErrIDUnauthorized = errorz.ID("unauthorized")
	ErrIDForbidden    = errorz.ID("forbidden")
)

Known error IDs.

Variables

This section is empty.

Functions

func NewErrBadRequest

func NewErrBadRequest(format string, options ...errorz.Option) error

NewErrBadRequest creates a new bad request error.

func NewErrForbidden

func NewErrForbidden(format string, options ...errorz.Option) error

NewErrForbidden creates a new forbidden error.

func NewErrUnauthorized

func NewErrUnauthorized(format string, options ...errorz.Option) error

NewErrUnauthorized creates a new unauthorized error.

func NoUnmarshalBody

func NoUnmarshalBody(u *jsonHTTPRequestUnmarshaler)

NoUnmarshalBody describes a JSONHTTPRequestUnmarshalerOption.

func NoUnmarshalPathParameters

func NoUnmarshalPathParameters(u *jsonHTTPRequestUnmarshaler)

NoUnmarshalPathParameters describes a JSONHTTPRequestUnmarshalerOption.

func NoUnmarshalQueryStringParameters

func NoUnmarshalQueryStringParameters(u *jsonHTTPRequestUnmarshaler)

NoUnmarshalQueryStringParameters describes a JSONHTTPRequestUnmarshalerOption.

func RequireExtractUser

func RequireExtractUser(u *jsonHTTPRequestUnmarshaler)

RequireExtractUser describes a JSONHTTPRequestUnmarshalerOption.

func WrapErrBadRequest

func WrapErrBadRequest(err error, options ...errorz.Option) error

WrapErrBadRequest wraps an error as bad request error.

func WrapErrForbidden

func WrapErrForbidden(err error, options ...errorz.Option) error

WrapErrForbidden wraps an error as forbidden error.

func WrapErrUnauthorized

func WrapErrUnauthorized(err error, options ...errorz.Option) error

WrapErrUnauthorized wraps an error as unauthorized error.

Types

type HTTPEndpoint

type HTTPEndpoint struct {
	// contains filtered or unexported fields
}

HTTPEndpoint describes an endpoint.

func NewHTTPEndpoint

func NewHTTPEndpoint(
	rawRouteKey string,
	requestAuthorizer HTTPRequestAuthorizer,
	requestUnmarshaler HTTPRequestUnmarshaler,
	responseMarshaler HTTPResponseMarshaler,
	errorMarshaler HTTPErrorMarshaler,
	handlerFunc interface{}) *HTTPEndpoint

NewHTTPEndpoint initializes a new HTTPEndpoint.

func (*HTTPEndpoint) GetRouteKey

func (e *HTTPEndpoint) GetRouteKey() *HTTPRouteKey

GetRouteKey returns the route key.

type HTTPErrorMarshaler

type HTTPErrorMarshaler interface {
	Marshal(ctx context.Context, err error) *events.APIGatewayV2HTTPResponse
}

HTTPErrorMarshaler describes a marshaler for a HTTP error.

func NewJSONHTTPErrorMarshaler

func NewJSONHTTPErrorMarshaler() HTTPErrorMarshaler

NewJSONHTTPErrorMarshaler initializes a new HTTPErrorMarshaler.

type HTTPMethod

type HTTPMethod string

HTTPMethod describes a HTTP method.

const (
	Any     HTTPMethod = "ANY"
	Delete  HTTPMethod = "DELETE"
	Get     HTTPMethod = "GET"
	Head    HTTPMethod = "HEAD"
	Options HTTPMethod = "OPTIONS"
	Patch   HTTPMethod = "PATCH"
	Post    HTTPMethod = "POST"
	Put     HTTPMethod = "PUT"
)

Known HTTP methods.

func (HTTPMethod) String

func (m HTTPMethod) String() string

String implements the fmt.Stringer interface.

func (HTTPMethod) Valid

func (m HTTPMethod) Valid() bool

Valid implements the vz.SimpleValidator interface.

type HTTPRequestAuthorizer

type HTTPRequestAuthorizer interface {
	Authorize(ctx context.Context) error
}

HTTPRequestAuthorizer describes an unmarshaler for a HTTP request.

func NewStaticAPIKeyHTTPRequestAuthorizer

func NewStaticAPIKeyHTTPRequestAuthorizer(apiKey string) HTTPRequestAuthorizer

NewStaticAPIKeyHTTPRequestAuthorizer initializes a new HTTPRequestAuthorizer

type HTTPRequestAuthorizerFunc

type HTTPRequestAuthorizerFunc func(ctx context.Context) error

HTTPRequestAuthorizerFunc implements the HTTPRequestAuthorizer interface.

func (HTTPRequestAuthorizerFunc) Authorize

Authorize a HTTP request.

type HTTPRequestContext

type HTTPRequestContext struct {
	// contains filtered or unexported fields
}

HTTPRequestContext describes the context for a HTTP request.

func GetHTTPRequestContext

func GetHTTPRequestContext(ctx context.Context) *HTTPRequestContext

GetHTTPRequestContext extracts the *HTTPRequestContext from context, panics on error.

func (*HTTPRequestContext) GetEvent

GetEvent returns the original APIGatewayV2HTTPRequest event.

type HTTPRequestUnmarshaler

type HTTPRequestUnmarshaler interface {
	GetRequestType() *reflect.Type
	Unmarshal(ctx context.Context) (interface{}, error)
}

HTTPRequestUnmarshaler describes an unmarshaler for a HTTP request.

func NewJSONHTTPRequestUnmarshaler

func NewJSONHTTPRequestUnmarshaler(reqTemplate interface{}, options ...JSONHTTPRequestUnmarshalerOption) HTTPRequestUnmarshaler

NewJSONHTTPRequestUnmarshaler initializes a new HTTPRequestUnmarshaler.

func NewNoBodyHTTPRequestUnmarshaler

func NewNoBodyHTTPRequestUnmarshaler(isStrict bool) HTTPRequestUnmarshaler

NewNoBodyHTTPRequestUnmarshaler initializes a new HTTPRequestUnmarshaler.

type HTTPResponseContext

type HTTPResponseContext struct {
	// contains filtered or unexported fields
}

HTTPResponseContext describes the context for a HTTP response.

func GetHTTPResponseContext

func GetHTTPResponseContext(ctx context.Context) *HTTPResponseContext

GetHTTPResponseContext extracts the *HTTPResponseContext from context, panics on error.

func (*HTTPResponseContext) AddCookie

func (c *HTTPResponseContext) AddCookie(cookie http.Cookie)

AddCookie adds a cookie to the response.

func (*HTTPResponseContext) GetHeaders

func (c *HTTPResponseContext) GetHeaders() http.Header

GetHeaders returns the editable response headers.

func (*HTTPResponseContext) SetStatus

func (c *HTTPResponseContext) SetStatus(status int)

SetStatus sets the response status.

type HTTPResponseMarshaler

type HTTPResponseMarshaler interface {
	GetResponseType() *reflect.Type
	Marshal(ctx context.Context, resp interface{}) *events.APIGatewayV2HTTPResponse
}

HTTPResponseMarshaler describes a marshaler for a HTTP response.

func NewJSONHTTPResponseMarshaler

func NewJSONHTTPResponseMarshaler(respTemplate interface{}) HTTPResponseMarshaler

NewJSONHTTPResponseMarshaler initializes a new HTTPResponseMarshaler.

func NewNoBodyHTTPResponseMarshaler

func NewNoBodyHTTPResponseMarshaler() HTTPResponseMarshaler

NewNoBodyHTTPResponseMarshaler initializes a new HTTPResponseMarshaler.

type HTTPRouteKey

type HTTPRouteKey struct {
	Raw       string
	IsDefault bool
	Method    HTTPMethod
	Path      string
}

HTTPRouteKey describes a parsed HTTP route key.

func ParseHTTPRouteKey

func ParseHTTPRouteKey(rawRouteKey string) (*HTTPRouteKey, error)

ParseHTTPRouteKey parses a HTTP route key. Note that the parsing logic is not particularly strict, rather designed to prevent accidental mistakes.

type HTTPRouter

type HTTPRouter struct {
	// contains filtered or unexported fields
}

HTTPRouter implements a HTTP router.

func NewHTTPRouter

func NewHTTPRouter() *HTTPRouter

NewHTTPRouter initializes a new HTTPRouter.

func (*HTTPRouter) GetEndpoints

func (r *HTTPRouter) GetEndpoints() []*HTTPEndpoint

GetEndpoints gets a slice of registered endpoints.

func (*HTTPRouter) Handler

Handler provides a handler function that can be registered with the Lambda SDK.

func (*HTTPRouter) Register

func (r *HTTPRouter) Register(endpoint *HTTPEndpoint) *HTTPRouter

Register registers an endpoint.

func (*HTTPRouter) SetInjector

func (r *HTTPRouter) SetInjector(injector injectz.Injector) *HTTPRouter

SetInjector sets the (optional) context injector.

func (*HTTPRouter) ShallowClone

func (r *HTTPRouter) ShallowClone() *HTTPRouter

ShallowClone returns a shallow clone of the router.

type JSONHTTPRequestUnmarshalerOption

type JSONHTTPRequestUnmarshalerOption func(u *jsonHTTPRequestUnmarshaler)

JSONHTTPRequestUnmarshalerOption describe an option for jsonHTTPRequestUnmarshaler.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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