Documentation ¶
Index ¶
- Variables
- func NewDynamoDBHandler(handlerFunc DynamoDBStreamHandlerFunc) func(ctx context.Context, r events.DynamoDBEvent) error
- func NewS3Handler(handlerFunc S3HandlerFunc) func(ctx context.Context, r events.S3Event) error
- type APIGatewayProxyContext
- func (c *APIGatewayProxyContext) Bind(v interface{}) error
- func (c *APIGatewayProxyContext) Created(location string) error
- func (c *APIGatewayProxyContext) Header(k, v string)
- func (c *APIGatewayProxyContext) JSON(statusCode int, body interface{}) error
- func (c *APIGatewayProxyContext) OK(body interface{}) error
- type APIGatewayProxyHandler
- type APIGatewayProxyHandlerFunc
- type DynamoDBContext
- type DynamoDBStreamHandler
- type DynamoDBStreamHandlerFunc
- type Err
- type S3Context
- type S3Handler
- type S3HandlerFunc
- type Validatable
Constants ¶
This section is empty.
Variables ¶
var ErrInternalServer = Err{ Status: http.StatusInternalServerError, Code: "INTERNAL_SERVER_ERROR", Detail: "Internal server error", }
ErrInternalServer is a standard error to represent server failures
var ErrInvalidBody = Err{ Status: http.StatusBadRequest, Code: "INVALID_REQUEST_BODY", Detail: "Invalid request body", }
ErrInvalidBody is a standard error to represent an invalid request body
Functions ¶
func NewDynamoDBHandler ¶ added in v0.5.1
func NewDynamoDBHandler(handlerFunc DynamoDBStreamHandlerFunc) func(ctx context.Context, r events.DynamoDBEvent) error
NewDynamoDBHandler adapts the lamb APIGatewayProxyHandlerFunc to the AWS lambda handler that is passed to lambda.Start
func NewS3Handler ¶ added in v0.5.0
NewS3Handler adapts the lamb APIGatewayProxyHandlerFunc to the AWS lambda handler that is passed to lambda.Start
Types ¶
type APIGatewayProxyContext ¶ added in v0.5.0
type APIGatewayProxyContext struct { Context context.Context Logger zerolog.Logger Request events.APIGatewayProxyRequest Response events.APIGatewayProxyResponse }
APIGatewayProxyContext provides convenience methods for working with API Gateway requests and responses
func (*APIGatewayProxyContext) Bind ¶ added in v0.5.0
func (c *APIGatewayProxyContext) Bind(v interface{}) error
Bind attempts to populate the provided struct with data from the HTTP request body. It also performs validation if the provided struct implements `Validatable`
func (*APIGatewayProxyContext) Created ¶ added in v0.5.0
func (c *APIGatewayProxyContext) Created(location string) error
Created is a convenient method for writing HTTP Status 201 API Gateway responses. It is opinionated in that it sets the resource location header. If you do not want this use
c.JSON(http.StatusCreated, nil)
instead.
func (*APIGatewayProxyContext) Header ¶ added in v0.5.0
func (c *APIGatewayProxyContext) Header(k, v string)
Header writes the provided header to the API Gateway response
func (*APIGatewayProxyContext) JSON ¶ added in v0.5.0
func (c *APIGatewayProxyContext) JSON(statusCode int, body interface{}) error
JSON writes the provided body and status code to the API Gateway response
func (*APIGatewayProxyContext) OK ¶ added in v0.5.0
func (c *APIGatewayProxyContext) OK(body interface{}) error
OK is a convenient method for writing the provided body and HTTP Status 200 to the API Gateway responses.
type APIGatewayProxyHandler ¶
type APIGatewayProxyHandler = func(ctx context.Context, r events.APIGatewayProxyRequest) (events.APIGatewayProxyResponse, error)
APIGatewayProxyHandler is the handler function for lambda events that originate from API Gateway
func NewAPIGatewayProxyHandler ¶ added in v0.5.0
func NewAPIGatewayProxyHandler(handlerFunc APIGatewayProxyHandlerFunc) APIGatewayProxyHandler
NewAPIGatewayProxyHandler adapts the lamb APIGatewayProxyHandlerFunc to the AWS lambda handler that is passed to lambda.Start
type APIGatewayProxyHandlerFunc ¶ added in v0.5.0
type APIGatewayProxyHandlerFunc func(ctx *APIGatewayProxyContext) error
APIGatewayProxyHandlerFunc is the lamb handler that users of this library implement. It gives access to convenience methods via `ctx`
type DynamoDBContext ¶ added in v0.5.1
type DynamoDBContext struct { Context context.Context Logger zerolog.Logger Event events.DynamoDBEventRecord }
APIGatewayProxyContext provides convenience methods for working with API Gateway requests and responses
func (*DynamoDBContext) Bind ¶ added in v0.5.1
func (c *DynamoDBContext) Bind(attributes map[string]events.DynamoDBAttributeValue, v interface{}) error
Bind attempts to populate the provided struct with data from the HTTP request body. It also performs validation if the provided struct implements `Validatable`
func (*DynamoDBContext) EventType ¶ added in v0.5.1
func (c *DynamoDBContext) EventType() events.DynamoDBOperationType
type DynamoDBStreamHandler ¶ added in v0.5.2
type DynamoDBStreamHandler func(ctx context.Context, r events.DynamoDBEvent) error
DynamoDBStreamHandler is the DynamoDB event handler func for AWS lambda
type DynamoDBStreamHandlerFunc ¶ added in v0.5.2
type DynamoDBStreamHandlerFunc func(ctx *DynamoDBContext) error
DynamoDBStreamHandlerFunc is the lamb handler that users of this library implement. It gives access to convenience methods via `ctx`
type Err ¶
type Err struct { Status int `json:"-"` Code string `json:"code"` Detail string `json:"detail"` Params interface{} `json:"params,omitempty"` }
Err is the error type returned to consumers of the API
type S3Context ¶ added in v0.5.0
APIGatewayProxyContext provides convenience methods for working with API Gateway requests and responses
type S3HandlerFunc ¶ added in v0.5.0
S3HandlerFunc is the lamb handler that users of this library implement. It gives access to convenience methods via `ctx`
type Validatable ¶
type Validatable interface {
Validate() error
}
Validatable is implemented by the request body struct. Example:
type requestBody struct { Name string `json:"name"` Status string `json:"status"` } func (b body) Validate() error { if b.Status == "" { return errors.New("status empty") } return nil }
This will then be validated in `ctx.Bind`