apigw

package
v0.4.8 Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2023 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	JsonMediaType               = "application/json"
	PlainTextMediaType          = "text/plain"
	HeaderAccessCtrlAllowOrigin = "Access-Control-Allow-Origin"
	HeaderContentType           = "Content-Type"
	WildCardMediaType           = "*/*"
)

Variables

This section is empty.

Functions

func BadRequest

func BadRequest(err error, body interface{}) events.APIGatewayProxyResponse

func FailureToGatewayResponse

func FailureToGatewayResponse(err error) events.APIGatewayProxyResponse

func GetAPIVersion

func GetAPIVersion(ctx context.Context) string

GetAPIVersion gets the api version from the context. Defaults to an empty string if not set.

func GetEvent

GetEvent gets the apigw event from the context. Defaults to a new empty instance if not set.

func GetIsCustomerServiceUser

func GetIsCustomerServiceUser(ctx context.Context) bool

GetIsCustomerServiceUser gets a boolean value on whether the user is a customer service user from the context. Defaults to false if not set.

func GetRoles

func GetRoles(ctx context.Context) string

GetRoles gets the users roles from the context. Defaults to an empty string if not set.

func GetUserID

func GetUserID(ctx context.Context) string

GetUserID gets the user id from the context. Defaults to an empty string if not set.

func InitializeRequestContext

func InitializeRequestContext(ctx context.Context, event events.APIGatewayProxyRequest) context.Context

func LambdaStart added in v0.4.5

func LambdaStart(config RestHandlerConfig, h Handler, logger *zap.SugaredLogger)

func SetAPIVersion

func SetAPIVersion(ctx context.Context, version string) context.Context

SetAPIVersion sets the api version in the context.

Types

type ErrorResponse

type ErrorResponse struct {
	Message string            `json:"message" `
	Fields  map[string]string `json:"fields,omitempty"`
	ID      string            `json:"id"`
	Status  int               `json:"status"`
}

ErrorResponse is the type used when returning an error from a handler. Message is the error message ID is the request id that can be used to find request details in a logging repository.

type Handler

type Handler interface {
	Run(ctx context.Context, e events.APIGatewayProxyRequest) (*Success, error)
}

type RestHandlerConfig

type RestHandlerConfig struct {
	sls.TimeoutConfig
}

type RestRunner

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

func NewRestRunner added in v0.4.5

func NewRestRunner(c RestHandlerConfig, h Handler, l *zap.SugaredLogger) *RestRunner

func (*RestRunner) Handle

func (h *RestRunner) Handle(ctx context.Context, req events.APIGatewayProxyRequest) (out interface{}, err error)

type Success

type Success struct {
	StatusCode int
	Headers    map[string]string

	Body      interface{}
	SuccessFn func(code int, body interface{}, l *zap.SugaredLogger, req events.APIGatewayProxyRequest) (events.APIGatewayProxyResponse, error)
}

func NoContent

func NoContent() *Success

func OK

func OK(body interface{}) *Success

func (*Success) AddHeader

func (s *Success) AddHeader(k, v string)

func (*Success) AddHeaders

func (s *Success) AddHeaders(h map[string]string)

Jump to

Keyboard shortcuts

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