Skip to content
Permalink
Browse files

add functions

  • Loading branch information...
vinta committed Apr 10, 2018
1 parent aa49d98 commit d03bd0463765302ae5246a1e773cfeb22e380d8b
Showing with 64 additions and 0 deletions.
  1. +5 −0 fixtures/spacing_text_event.json
  2. +50 −0 functions/spacing_text/main.go
  3. +9 −0 project.json
@@ -0,0 +1,5 @@
{
"queryStringParameters": {
"t": "當你凝視著bug,bug也凝視著你"
}
}
@@ -0,0 +1,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 is thrown when text is not provided
ErrTextNotProvided = errors.New("No text was provided in the HTTP query string")
)

// Handler is the AWS Lambda function handler
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)
}
@@ -0,0 +1,9 @@
{
"name": "panguspace",
"description": "A Pangu project",
"runtime": "golang",
"memory": 128,
"timeout": 5,
"role": "arn:aws:iam::004615714446:role/panguspace_lambda_function",
"environment": {}
}

0 comments on commit d03bd04

Please sign in to comment.
You can’t perform that action at this time.