Skip to content

Commit d93f542

Browse files
authored
Merge pull request #8 from scaleway/fix_golang_example
[Fix/Examples/Go] add examples for golang runtime
2 parents 9d55fc0 + ce1fed6 commit d93f542

File tree

3 files changed

+40
-3
lines changed

3 files changed

+40
-3
lines changed

docs/README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,9 +168,10 @@ functions:
168168
```
169169
- src
170170
- testing
171-
- handler.go -> package testing
171+
- handler.go -> package main inside "src/testing" directory
172172
- second
173-
- handler.go -> package second
173+
- handler.go -> package main inside "src/second" directory
174+
- handler.go -> package main at the root of the project
174175
- serverless.yml
175176
```
176177
Your serverless.yml `functions` should look something like this:
@@ -179,6 +180,8 @@ provider:
179180
# ...
180181
runtime: golang
181182
functions:
183+
root:
184+
handler: "."
182185
testing:
183186
handler: src/testing
184187
second:
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package main
2+
3+
import (
4+
"encoding/json"
5+
6+
"github.com/scaleway/scaleway-functions-go/events"
7+
"github.com/scaleway/scaleway-functions-go/lambda"
8+
)
9+
10+
// Handler - Handle event
11+
func Handler(req events.APIGatewayProxyRequest) (events.APIGatewayProxyResponse, error) {
12+
response := map[string]interface{}{
13+
"message": "My Custom Package",
14+
}
15+
16+
responseB, err := json.Marshal(response)
17+
if err != nil {
18+
return events.APIGatewayProxyResponse{}, err
19+
}
20+
21+
return events.APIGatewayProxyResponse{
22+
Body: string(responseB),
23+
StatusCode: 200,
24+
}, nil
25+
}
26+
27+
func main() {
28+
lambda.Start(Handler)
29+
}

examples/golang/serverless.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,12 @@ package:
2222

2323
functions:
2424
first:
25-
handler: function
25+
# If handler is at the root of your serverless project
26+
handler: "."
2627
# Local environment variables - used only in given function
2728
env:
2829
local: local
30+
31+
mypackage:
32+
# if your handler is in a custom package
33+
handler: mypackage

0 commit comments

Comments
 (0)