1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
| package main
import ( "encoding/json" "errors" "log"
"github.com/aws/aws-lambda-go/events" "github.com/aws/aws-lambda-go/lambda" "github.com/vinta/pangu" )
var ( ErrTextNotProvided = errors.New("No text was provided in HTTP query string") )
func Handler(request events.APIGatewayProxyRequest) (events.APIGatewayProxyResponse, error) { log.Printf("request id: %s\n", request.RequestContext.RequestID)
text, ok := request.QueryStringParameters["t"] if !ok { errMap := map[string]string{ "message": ErrTextNotProvided.Error(), } errMapJSON, _ := json.MarshalIndent(errMap, "", " ")
return events.APIGatewayProxyResponse{ Body: string(errMapJSON), StatusCode: 400, }, nil }
log.Printf("text: %s\n", text)
textPlainHeaders := map[string]string{ "content-type": "text/plain; charset=utf-8", } return events.APIGatewayProxyResponse{ Body: pangu.SpacingText(text), Headers: textPlainHeaders, StatusCode: 200, }, nil }
func main() { lambda.Start(Handler) }
|