Skip to content

Commit

Permalink
feat: added scheduled functions template for Go (#4495)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
karagulamos and karagulamos authored Mar 30, 2022
1 parent 9a1573b commit 17726b3
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"Cole Bosmann",
"Dan Croak (https://twitter.com/croaky)",
"Dan Loewenherz <dan@lionheartsw.com> (https://twitter.com/dwlz)",
"Daniel Woelfel <dwwoelfel@gmail.com> (https://twitter.com/danielwoelfel)",
"Dave Ackerman <dmackerman@gmail.com>",
"David Calavera <david@netlify.com> (https://twitter.com/calavera)",
"David Lemler <dlemler@pm.me> (https://twitter.com/davidlemlerm)",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
name: 'scheduled-function',
priority: 1,
description: 'Basic implementation of a scheduled function in Go.',
}
5 changes: 5 additions & 0 deletions src/functions-templates/go/scheduled-function/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module github.com/your-github-handle/{{name}}

go 1.17

require github.com/aws/aws-lambda-go v1.28.0
21 changes: 21 additions & 0 deletions src/functions-templates/go/scheduled-function/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/aws/aws-lambda-go v1.28.0 h1:fZiik1PZqW2IyAN4rj+Y0UBaO1IDFlsNo9Zz/XnArK4=
github.com/aws/aws-lambda-go v1.28.0/go.mod h1:jJmlefzPfGnckuHdXX7/80O3BvUUi12XOkbv4w9SGLU=
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/urfave/cli/v2 v2.2.0/go.mod h1:SE9GqnLQmjVa0iPEY0f1w3ygNIYcIJ0OKPMoW2caLfQ=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776 h1:tQIYjPdBoyREyB9XMu+nnTclpTYkz2zFM+lzLJFO4gQ=
gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
11 changes: 11 additions & 0 deletions src/functions-templates/go/scheduled-function/netlify.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[build]
functions = "functions"

[build.environment]
GO_VERSION = "1.17"

[functions]
directory = "src/"

[functions.hourly-schedule]
schedule = "@hourly"
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package main

import (
"context"
"encoding/json"
"log"
"net/http"
"time"

"github.com/aws/aws-lambda-go/events"
"github.com/aws/aws-lambda-go/lambda"
)

type requestBody struct {
NextRun time.Time `json:"next_run"`
}

// The schedule for this function is defined inside the netlify.toml file. To learn about scheduled functions
// and supported cron extensions, visit https://ntl.fyi/sched-func.
func handler(ctx context.Context, request events.APIGatewayProxyRequest) (*events.APIGatewayProxyResponse, error) {
requestBody := requestBody{}

if err := json.Unmarshal([]byte(request.Body), &requestBody); err != nil {
log.Fatalf("cannot parse request body: %s", err.Error())
}

log.Printf("Next run at %s\n", requestBody.NextRun.Local())

return &events.APIGatewayProxyResponse{
StatusCode: http.StatusNoContent,
}, nil
}

func main() {
lambda.Start(handler)
}

1 comment on commit 17726b3

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📊 Benchmark results

Package size: 380 MB

Please sign in to comment.