func handler(request events.APIGatewayProxyRequest) (events.APIGatewayProxyResponse, error) {
method := request.HTTPMethod
ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
defer cancel()
if client == nil {
return handleError(errors.New("No connection to DB"))
}
switch method {
case getMethod:
return getStories(ctx)
case postMethod:
return postStory(ctx, request.Body)
case putMethod:
return updateStory(ctx, request.Body)
default:
return defaultReturn()
}
}
view raw pt-2.main.go hosted with ❤ by GitHub