Skip to content

Commit 17726b3

Browse files
authoredMar 30, 2022
feat: added scheduled functions template for Go (#4495)
* feat: go scheduled functions template * chore: update contributors field * chore: placeholder for github handle in go mod * chore: remove unnecessary makefile * chore: go version update Co-authored-by: karagulamos <karagulamos@users.noreply.github.com>
1 parent 9a1573b commit 17726b3

File tree

6 files changed

+79
-0
lines changed

6 files changed

+79
-0
lines changed
 

‎package.json

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
"Cole Bosmann",
3131
"Dan Croak (https://twitter.com/croaky)",
3232
"Dan Loewenherz <dan@lionheartsw.com> (https://twitter.com/dwlz)",
33+
"Daniel Woelfel <dwwoelfel@gmail.com> (https://twitter.com/danielwoelfel)",
3334
"Dave Ackerman <dmackerman@gmail.com>",
3435
"David Calavera <david@netlify.com> (https://twitter.com/calavera)",
3536
"David Lemler <dlemler@pm.me> (https://twitter.com/davidlemlerm)",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module.exports = {
2+
name: 'scheduled-function',
3+
priority: 1,
4+
description: 'Basic implementation of a scheduled function in Go.',
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module github.com/your-github-handle/{{name}}
2+
3+
go 1.17
4+
5+
require github.com/aws/aws-lambda-go v1.28.0
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
2+
github.com/aws/aws-lambda-go v1.28.0 h1:fZiik1PZqW2IyAN4rj+Y0UBaO1IDFlsNo9Zz/XnArK4=
3+
github.com/aws/aws-lambda-go v1.28.0/go.mod h1:jJmlefzPfGnckuHdXX7/80O3BvUUi12XOkbv4w9SGLU=
4+
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
5+
github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
6+
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
7+
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
8+
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
9+
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
10+
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
11+
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
12+
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
13+
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
14+
github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
15+
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
16+
github.com/urfave/cli/v2 v2.2.0/go.mod h1:SE9GqnLQmjVa0iPEY0f1w3ygNIYcIJ0OKPMoW2caLfQ=
17+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
18+
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
19+
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
20+
gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776 h1:tQIYjPdBoyREyB9XMu+nnTclpTYkz2zFM+lzLJFO4gQ=
21+
gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[build]
2+
functions = "functions"
3+
4+
[build.environment]
5+
GO_VERSION = "1.17"
6+
7+
[functions]
8+
directory = "src/"
9+
10+
[functions.hourly-schedule]
11+
schedule = "@hourly"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package main
2+
3+
import (
4+
"context"
5+
"encoding/json"
6+
"log"
7+
"net/http"
8+
"time"
9+
10+
"github.com/aws/aws-lambda-go/events"
11+
"github.com/aws/aws-lambda-go/lambda"
12+
)
13+
14+
type requestBody struct {
15+
NextRun time.Time `json:"next_run"`
16+
}
17+
18+
// The schedule for this function is defined inside the netlify.toml file. To learn about scheduled functions
19+
// and supported cron extensions, visit https://ntl.fyi/sched-func.
20+
func handler(ctx context.Context, request events.APIGatewayProxyRequest) (*events.APIGatewayProxyResponse, error) {
21+
requestBody := requestBody{}
22+
23+
if err := json.Unmarshal([]byte(request.Body), &requestBody); err != nil {
24+
log.Fatalf("cannot parse request body: %s", err.Error())
25+
}
26+
27+
log.Printf("Next run at %s\n", requestBody.NextRun.Local())
28+
29+
return &events.APIGatewayProxyResponse{
30+
StatusCode: http.StatusNoContent,
31+
}, nil
32+
}
33+
34+
func main() {
35+
lambda.Start(handler)
36+
}

1 commit comments

Comments
 (1)

github-actions[bot] commented on Mar 30, 2022

@github-actions[bot]

📊 Benchmark results

Package size: 380 MB

Please sign in to comment.