From 5b56228594f67fcea3e06b8fab692c3909ad339e Mon Sep 17 00:00:00 2001 From: AmFlint Date: Fri, 5 Jul 2019 12:06:47 +0200 Subject: [PATCH 1/2] [Fix/Examples/Go] add examples for golang runtime --- examples/golang/mypackage/handler.go | 29 ++++++++++++++++++++++++++++ examples/golang/serverless.yml | 7 ++++++- 2 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 examples/golang/mypackage/handler.go diff --git a/examples/golang/mypackage/handler.go b/examples/golang/mypackage/handler.go new file mode 100644 index 00000000..bb6be77a --- /dev/null +++ b/examples/golang/mypackage/handler.go @@ -0,0 +1,29 @@ +package main + +import ( + "encoding/json" + + "github.com/scaleway/scaleway-functions-go/events" + "github.com/scaleway/scaleway-functions-go/lambda" +) + +// Handler - Handle event +func Handler(req events.APIGatewayProxyRequest) (events.APIGatewayProxyResponse, error) { + response := map[string]interface{}{ + "message": "My Custom Package", + } + + responseB, err := json.Marshal(response) + if err != nil { + return events.APIGatewayProxyResponse{}, err + } + + return events.APIGatewayProxyResponse{ + Body: string(responseB), + StatusCode: 200, + }, nil +} + +func main() { + lambda.Start(Handler) +} diff --git a/examples/golang/serverless.yml b/examples/golang/serverless.yml index 34094192..f5d1e10b 100644 --- a/examples/golang/serverless.yml +++ b/examples/golang/serverless.yml @@ -22,7 +22,12 @@ package: functions: first: - handler: function + # If handler is at the root of your serverless project + handler: "." # Local environment variables - used only in given function env: local: local + + mypackage: + # if your handler is in a custom package + handler: mypackage From ce1fed6953d0334ac9a56e0577036355696aabf3 Mon Sep 17 00:00:00 2001 From: AmFlint Date: Fri, 5 Jul 2019 12:09:49 +0200 Subject: [PATCH 2/2] [Doc/Runtimes/Go] add doc for root package handlers for golang --- docs/README.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/docs/README.md b/docs/README.md index c2d68f00..dd27e649 100644 --- a/docs/README.md +++ b/docs/README.md @@ -168,9 +168,10 @@ functions: ``` - src - testing - - handler.go -> package testing + - handler.go -> package main inside "src/testing" directory - second - - handler.go -> package second + - handler.go -> package main inside "src/second" directory +- handler.go -> package main at the root of the project - serverless.yml ``` Your serverless.yml `functions` should look something like this: @@ -179,6 +180,8 @@ provider: # ... runtime: golang functions: + root: + handler: "." testing: handler: src/testing second: