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() | |
} | |
} |