From 6eebd8cfdf4a5af3093c6429ec6b4a06a7bc49c4 Mon Sep 17 00:00:00 2001 From: Bryan Moffatt Date: Tue, 9 Aug 2022 21:25:55 -0700 Subject: [PATCH 1/3] add 1.19 to the unit test matrix --- .github/workflows/tests.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 14e115d8..662f6e9b 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -10,6 +10,7 @@ jobs: strategy: matrix: go: + - "1.19" - "1.18" - "1.17" - "1.16" From 9254f38280a358aeac4fd7f06c5467543b80bdea Mon Sep 17 00:00:00 2001 From: Bryan Moffatt Date: Tue, 9 Aug 2022 21:54:22 -0700 Subject: [PATCH 2/3] use v1.48.0 golangci-lint in workflows --- .github/workflows/lint.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 56de84a3..5a4086ac 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -18,6 +18,6 @@ jobs: - name: golangci-golint run: | - curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s v1.45.0 + curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s v1.48.0 ./bin/golangci-lint run -v ./... From 69f2b2ac4401f08beabd0b7b732168912eb0b2db Mon Sep 17 00:00:00 2001 From: Bryan Moffatt Date: Tue, 9 Aug 2022 22:09:01 -0700 Subject: [PATCH 3/3] ignore linter warnings about ioutil package rename, and reformat with go 1.19 version of gofmt --- cfn/event_test.go | 2 +- cfn/response.go | 2 +- cfn/wrap.go | 14 +++---- cfn/wrap_test.go | 2 +- cmd/build-lambda-zip/main.go | 2 +- cmd/build-lambda-zip/main_test.go | 2 +- cmd/build-lambda-zip/testdata/apigw.go | 4 +- cmd/build-lambda-zip/testdata/noop.go | 3 +- events/alb_test.go | 2 +- events/apigw_test.go | 2 +- events/appsync_test.go | 2 +- events/clientvpn_test.go | 2 +- events/codebuild.go | 2 +- events/codebuild_test.go | 2 +- events/codedeploy_test.go | 2 +- events/codepipeline.go | 3 +- events/codepipeline_cloudwatch_test.go | 2 +- events/codepipeline_job_test.go | 2 +- events/codepipeline_test.go | 2 +- events/cognito_test.go | 2 +- events/config_test.go | 2 +- events/iot_test.go | 2 +- events/lambda_function_urls_test.go | 2 +- events/test/assert.go | 6 +-- events/test/jsonblobs.go | 2 +- events/test/jsonsyntax.go | 2 +- events/test/readjson.go | 2 +- lambda/entry.go | 34 ++++++++-------- lambda/extensions_api_client.go | 2 +- lambda/handler.go | 56 ++++++++++++++------------ lambda/runtime_api_client.go | 10 ++--- lambda/runtime_api_client_test.go | 2 +- lambda/sigterm_test.go | 2 +- 33 files changed, 93 insertions(+), 87 deletions(-) diff --git a/cfn/event_test.go b/cfn/event_test.go index 46d154aa..9d22ad01 100644 --- a/cfn/event_test.go +++ b/cfn/event_test.go @@ -4,7 +4,7 @@ package cfn import ( "encoding/json" - "io/ioutil" + "io/ioutil" //nolint: staticcheck "testing" "github.com/aws/aws-lambda-go/events/test" diff --git a/cfn/response.go b/cfn/response.go index 7f84f033..375ddcb8 100644 --- a/cfn/response.go +++ b/cfn/response.go @@ -6,7 +6,7 @@ import ( "bytes" "encoding/json" "fmt" - "io/ioutil" + "io/ioutil" //nolint: staticcheck "log" "net/http" ) diff --git a/cfn/wrap.go b/cfn/wrap.go index 1bf6487d..ab421a85 100644 --- a/cfn/wrap.go +++ b/cfn/wrap.go @@ -71,14 +71,14 @@ func lambdaWrapWithClient(lambdaFunction CustomResourceFunction, client httpClie // plate is taken away from the customer and it makes writing a Custom Resource // simpler. // -// func myLambda(ctx context.Context, event cfn.Event) (physicalResourceID string, data map[string]interface{}, err error) { -// physicalResourceID = "arn:...." -// return -// } +// func myLambda(ctx context.Context, event cfn.Event) (physicalResourceID string, data map[string]interface{}, err error) { +// physicalResourceID = "arn:...." +// return +// } // -// func main() { -// lambda.Start(cfn.LambdaWrap(myLambda)) -// } +// func main() { +// lambda.Start(cfn.LambdaWrap(myLambda)) +// } func LambdaWrap(lambdaFunction CustomResourceFunction) (fn CustomResourceLambdaFunction) { return lambdaWrapWithClient(lambdaFunction, http.DefaultClient) } diff --git a/cfn/wrap_test.go b/cfn/wrap_test.go index e4ac5f92..da98f20f 100644 --- a/cfn/wrap_test.go +++ b/cfn/wrap_test.go @@ -7,7 +7,7 @@ import ( "context" "encoding/json" "errors" - "io/ioutil" + "io/ioutil" //nolint: staticcheck "net/http" "testing" diff --git a/cmd/build-lambda-zip/main.go b/cmd/build-lambda-zip/main.go index d0c5efb2..80a45334 100644 --- a/cmd/build-lambda-zip/main.go +++ b/cmd/build-lambda-zip/main.go @@ -6,7 +6,7 @@ import ( "archive/zip" "flag" "fmt" - "io/ioutil" + "io/ioutil" //nolint: staticcheck "log" "os" "path/filepath" diff --git a/cmd/build-lambda-zip/main_test.go b/cmd/build-lambda-zip/main_test.go index 0e1571fd..6def4c49 100644 --- a/cmd/build-lambda-zip/main_test.go +++ b/cmd/build-lambda-zip/main_test.go @@ -5,7 +5,7 @@ package main import ( "archive/zip" "fmt" - "io/ioutil" + "io/ioutil" //nolint: staticcheck "os" "os/exec" "path" diff --git a/cmd/build-lambda-zip/testdata/apigw.go b/cmd/build-lambda-zip/testdata/apigw.go index 31e95f19..1e3b93d9 100644 --- a/cmd/build-lambda-zip/testdata/apigw.go +++ b/cmd/build-lambda-zip/testdata/apigw.go @@ -9,8 +9,8 @@ import ( "github.com/aws/aws-lambda-go/lambda" ) -func main () { - lambda.Start(func (ctx context.Context, event events.APIGatewayV2HTTPRequest) (*events.APIGatewayProxyResponse, error) { +func main() { + lambda.Start(func(ctx context.Context, event events.APIGatewayV2HTTPRequest) (*events.APIGatewayProxyResponse, error) { return &events.APIGatewayProxyResponse{ Body: fmt.Sprintf("Hello %v", event), }, nil diff --git a/cmd/build-lambda-zip/testdata/noop.go b/cmd/build-lambda-zip/testdata/noop.go index 23dde4af..f94da720 100644 --- a/cmd/build-lambda-zip/testdata/noop.go +++ b/cmd/build-lambda-zip/testdata/noop.go @@ -8,11 +8,12 @@ import ( ) type BinaryHandler func(context.Context, []byte) ([]byte, error) + func (bh BinaryHandler) Invoke(ctx context.Context, req []byte) ([]byte, error) { return bh(ctx, req) } -func noop (ctx context.Context, req []byte) ([]byte, error) { +func noop(ctx context.Context, req []byte) ([]byte, error) { return req, nil } diff --git a/events/alb_test.go b/events/alb_test.go index e4ccc798..56d5b963 100644 --- a/events/alb_test.go +++ b/events/alb_test.go @@ -2,7 +2,7 @@ package events import ( "encoding/json" - "io/ioutil" + "io/ioutil" //nolint: staticcheck "testing" "github.com/aws/aws-lambda-go/events/test" diff --git a/events/apigw_test.go b/events/apigw_test.go index 8aa7d87e..5957e96a 100644 --- a/events/apigw_test.go +++ b/events/apigw_test.go @@ -4,7 +4,7 @@ package events import ( "encoding/json" - "io/ioutil" + "io/ioutil" //nolint: staticcheck "testing" "github.com/aws/aws-lambda-go/events/test" diff --git a/events/appsync_test.go b/events/appsync_test.go index 7ba8f0e3..2e179261 100644 --- a/events/appsync_test.go +++ b/events/appsync_test.go @@ -2,7 +2,7 @@ package events import ( "encoding/json" - "io/ioutil" + "io/ioutil" //nolint: staticcheck "testing" "github.com/aws/aws-lambda-go/events/test" diff --git a/events/clientvpn_test.go b/events/clientvpn_test.go index 356790ab..aae58d59 100644 --- a/events/clientvpn_test.go +++ b/events/clientvpn_test.go @@ -2,7 +2,7 @@ package events import ( "encoding/json" - "io/ioutil" + "io/ioutil" //nolint: staticcheck "testing" "github.com/aws/aws-lambda-go/events/test" diff --git a/events/codebuild.go b/events/codebuild.go index 2a464829..08cbb607 100644 --- a/events/codebuild.go +++ b/events/codebuild.go @@ -93,7 +93,7 @@ type CodeBuildEventDetail struct { CompletedPhaseEnd CodeBuildTime `json:"completed-phase-end"` } -//CodeBuildEventAdditionalInformation represents additional information to the code build event +// CodeBuildEventAdditionalInformation represents additional information to the code build event type CodeBuildEventAdditionalInformation struct { Artifact CodeBuildArtifact `json:"artifact"` diff --git a/events/codebuild_test.go b/events/codebuild_test.go index e0ea6646..d0e1b693 100644 --- a/events/codebuild_test.go +++ b/events/codebuild_test.go @@ -2,7 +2,7 @@ package events import ( "encoding/json" - "io/ioutil" + "io/ioutil" //nolint: staticcheck "testing" "time" diff --git a/events/codedeploy_test.go b/events/codedeploy_test.go index 871d03f4..c363f77d 100644 --- a/events/codedeploy_test.go +++ b/events/codedeploy_test.go @@ -3,7 +3,7 @@ package events import ( "encoding/json" "github.com/stretchr/testify/require" - "io/ioutil" + "io/ioutil" //nolint: staticcheck "testing" "time" ) diff --git a/events/codepipeline.go b/events/codepipeline.go index 2134cbb5..4e15de57 100644 --- a/events/codepipeline.go +++ b/events/codepipeline.go @@ -1,6 +1,7 @@ package events // CodePipelineJob has been incorrectly assigned as CodePipelineEvent -// - https://github.com/aws/aws-lambda-go/issues/244 +// - https://github.com/aws/aws-lambda-go/issues/244 +// // This maintains backwards compatability until a v2 release type CodePipelineEvent = CodePipelineJobEvent diff --git a/events/codepipeline_cloudwatch_test.go b/events/codepipeline_cloudwatch_test.go index e927e705..e1e21748 100644 --- a/events/codepipeline_cloudwatch_test.go +++ b/events/codepipeline_cloudwatch_test.go @@ -3,7 +3,7 @@ package events import ( "encoding/json" "github.com/stretchr/testify/require" - "io/ioutil" + "io/ioutil" //nolint: staticcheck "testing" "time" ) diff --git a/events/codepipeline_job_test.go b/events/codepipeline_job_test.go index 6f1143eb..c78bfa0d 100644 --- a/events/codepipeline_job_test.go +++ b/events/codepipeline_job_test.go @@ -3,7 +3,7 @@ package events import ( "encoding/json" - "io/ioutil" + "io/ioutil" //nolint: staticcheck "testing" "github.com/aws/aws-lambda-go/events/test" diff --git a/events/codepipeline_test.go b/events/codepipeline_test.go index 063ea0b3..cb7e0e6a 100644 --- a/events/codepipeline_test.go +++ b/events/codepipeline_test.go @@ -3,7 +3,7 @@ package events import ( "encoding/json" - "io/ioutil" + "io/ioutil" //nolint: staticcheck "testing" "github.com/aws/aws-lambda-go/events/test" diff --git a/events/cognito_test.go b/events/cognito_test.go index fdb1d437..88cb3121 100644 --- a/events/cognito_test.go +++ b/events/cognito_test.go @@ -3,7 +3,7 @@ package events import ( "encoding/json" - "io/ioutil" + "io/ioutil" //nolint: staticcheck "testing" "github.com/aws/aws-lambda-go/events/test" diff --git a/events/config_test.go b/events/config_test.go index d7f55b87..57b31123 100644 --- a/events/config_test.go +++ b/events/config_test.go @@ -3,7 +3,7 @@ package events import ( "encoding/json" - "io/ioutil" + "io/ioutil" //nolint: staticcheck "testing" "github.com/aws/aws-lambda-go/events/test" diff --git a/events/iot_test.go b/events/iot_test.go index 015a13fb..38cf84e9 100644 --- a/events/iot_test.go +++ b/events/iot_test.go @@ -2,7 +2,7 @@ package events import ( "encoding/json" - "io/ioutil" + "io/ioutil" //nolint: staticcheck "testing" "github.com/aws/aws-lambda-go/events/test" diff --git a/events/lambda_function_urls_test.go b/events/lambda_function_urls_test.go index 17c511d8..0b11a048 100644 --- a/events/lambda_function_urls_test.go +++ b/events/lambda_function_urls_test.go @@ -4,7 +4,7 @@ package events import ( "encoding/json" - "io/ioutil" + "io/ioutil" //nolint: staticcheck "testing" "github.com/stretchr/testify/assert" diff --git a/events/test/assert.go b/events/test/assert.go index 0ac4f212..14040740 100644 --- a/events/test/assert.go +++ b/events/test/assert.go @@ -2,13 +2,13 @@ package test import ( "encoding/json" - "io/ioutil" + "io/ioutil" //nolint: staticcheck "testing" "github.com/stretchr/testify/assert" ) -//nolint: stylecheck +// nolint: stylecheck func AssertJsonFile(t *testing.T, file string, o interface{}) { inputJSON, err := ioutil.ReadFile(file) if err != nil { @@ -17,7 +17,7 @@ func AssertJsonFile(t *testing.T, file string, o interface{}) { AssertJsonBytes(t, inputJSON, o) } -//nolint: stylecheck +// nolint: stylecheck func AssertJsonBytes(t *testing.T, inputJSON []byte, o interface{}) { // de-serialize if err := json.Unmarshal(inputJSON, o); err != nil { diff --git a/events/test/jsonblobs.go b/events/test/jsonblobs.go index 95eb288a..4b17f924 100644 --- a/events/test/jsonblobs.go +++ b/events/test/jsonblobs.go @@ -1,6 +1,6 @@ package test -//nolint: stylecheck +// nolint: stylecheck func GetMalformedJson() []byte { return []byte(`{ "Records`) } diff --git a/events/test/jsonsyntax.go b/events/test/jsonsyntax.go index b9a2d1f0..9c4b0067 100644 --- a/events/test/jsonsyntax.go +++ b/events/test/jsonsyntax.go @@ -7,7 +7,7 @@ import ( "testing" ) -//nolint: stylecheck +// nolint: stylecheck func TestMalformedJson(t *testing.T, objectToDeserialize interface{}) { // 1. read JSON from file inputJson := GetMalformedJson() diff --git a/events/test/readjson.go b/events/test/readjson.go index 9a97b9b0..bb742192 100644 --- a/events/test/readjson.go +++ b/events/test/readjson.go @@ -1,7 +1,7 @@ package test import ( - "io/ioutil" + "io/ioutil" //nolint: staticcheck "testing" ) diff --git a/lambda/entry.go b/lambda/entry.go index c935e236..6c1d7194 100644 --- a/lambda/entry.go +++ b/lambda/entry.go @@ -14,24 +14,24 @@ import ( // // Rules: // -// * handler must be a function -// * handler may take between 0 and two arguments. -// * if there are two arguments, the first argument must satisfy the "context.Context" interface. -// * handler may return between 0 and two arguments. -// * if there are two return values, the second argument must be an error. -// * if there is one return value it must be an error. +// - handler must be a function +// - handler may take between 0 and two arguments. +// - if there are two arguments, the first argument must satisfy the "context.Context" interface. +// - handler may return between 0 and two arguments. +// - if there are two return values, the second argument must be an error. +// - if there is one return value it must be an error. // // Valid function signatures: // -// func () -// func () error -// func (TIn) error -// func () (TOut, error) -// func (TIn) (TOut, error) -// func (context.Context) error -// func (context.Context, TIn) error -// func (context.Context) (TOut, error) -// func (context.Context, TIn) (TOut, error) +// func () +// func () error +// func (TIn) error +// func () (TOut, error) +// func (TIn) (TOut, error) +// func (context.Context) error +// func (context.Context, TIn) error +// func (context.Context) (TOut, error) +// func (context.Context, TIn) (TOut, error) // // Where "TIn" and "TOut" are types compatible with the "encoding/json" standard library. // See https://golang.org/pkg/encoding/json/#Unmarshal for how deserialization behaves @@ -51,7 +51,7 @@ func StartWithContext(ctx context.Context, handler interface{}) { // // Handler implementation requires a single "Invoke()" function: // -// func Invoke(context.Context, []byte) ([]byte, error) +// func Invoke(context.Context, []byte) ([]byte, error) // // Deprecated: use lambda.Start(handler) instead func StartHandler(handler Handler) { @@ -83,7 +83,7 @@ var ( // // Handler implementation requires a single "Invoke()" function: // -// func Invoke(context.Context, []byte) ([]byte, error) +// func Invoke(context.Context, []byte) ([]byte, error) // // Deprecated: use lambda.StartWithOptions(handler, lambda.WithContext(ctx)) instead func StartHandlerWithContext(ctx context.Context, handler Handler) { diff --git a/lambda/extensions_api_client.go b/lambda/extensions_api_client.go index e17292b3..c9703891 100644 --- a/lambda/extensions_api_client.go +++ b/lambda/extensions_api_client.go @@ -5,7 +5,7 @@ import ( "encoding/json" "fmt" "io" - "io/ioutil" + "io/ioutil" //nolint: staticcheck "net/http" ) diff --git a/lambda/handler.go b/lambda/handler.go index d23a789b..0fc82d6e 100644 --- a/lambda/handler.go +++ b/lambda/handler.go @@ -32,12 +32,13 @@ type Option func(*handlerOptions) // WithContext is a HandlerOption that sets the base context for all invocations of the handler. // // Usage: -// lambda.StartWithOptions( -// func (ctx context.Context) (string, error) { -// return ctx.Value("foo"), nil -// }, -// lambda.WithContext(context.WithValue(context.Background(), "foo", "bar")) -// ) +// +// lambda.StartWithOptions( +// func (ctx context.Context) (string, error) { +// return ctx.Value("foo"), nil +// }, +// lambda.WithContext(context.WithValue(context.Background(), "foo", "bar")) +// ) func WithContext(ctx context.Context) Option { return Option(func(h *handlerOptions) { h.baseContext = ctx @@ -47,12 +48,13 @@ func WithContext(ctx context.Context) Option { // WithSetEscapeHTML sets the SetEscapeHTML argument on the underlying json encoder // // Usage: -// lambda.StartWithOptions( -// func () (string, error) { -// return "hello!>", nil -// }, -// lambda.WithSetEscapeHTML(true), -// ) +// +// lambda.StartWithOptions( +// func () (string, error) { +// return "hello!>", nil +// }, +// lambda.WithSetEscapeHTML(true), +// ) func WithSetEscapeHTML(escapeHTML bool) Option { return Option(func(h *handlerOptions) { h.jsonResponseEscapeHTML = escapeHTML @@ -62,12 +64,13 @@ func WithSetEscapeHTML(escapeHTML bool) Option { // WithSetIndent sets the SetIndent argument on the underling json encoder // // Usage: -// lambda.StartWithOptions( -// func (event any) (any, error) { -// return event, nil -// }, -// lambda.WithSetIndent(">"," "), -// ) +// +// lambda.StartWithOptions( +// func (event any) (any, error) { +// return event, nil +// }, +// lambda.WithSetIndent(">"," "), +// ) func WithSetIndent(prefix, indent string) Option { return Option(func(h *handlerOptions) { h.jsonResponseIndentPrefix = prefix @@ -80,14 +83,15 @@ func WithSetIndent(prefix, indent string) Option { // Optionally, an array of callback functions to run on SIGTERM may be provided. // // Usage: -// lambda.StartWithOptions( -// func (event any) (any, error) { -// return event, nil -// }, -// lambda.WithEnableSIGTERM(func() { -// log.Print("function container shutting down...") -// }) -// ) +// +// lambda.StartWithOptions( +// func (event any) (any, error) { +// return event, nil +// }, +// lambda.WithEnableSIGTERM(func() { +// log.Print("function container shutting down...") +// }) +// ) func WithEnableSIGTERM(callbacks ...func()) Option { return Option(func(h *handlerOptions) { h.sigtermCallbacks = append(h.sigtermCallbacks, callbacks...) diff --git a/lambda/runtime_api_client.go b/lambda/runtime_api_client.go index 637a5411..843f7ace 100644 --- a/lambda/runtime_api_client.go +++ b/lambda/runtime_api_client.go @@ -8,7 +8,7 @@ import ( "bytes" "fmt" "io" - "io/ioutil" + "io/ioutil" //nolint: staticcheck "log" "net/http" "runtime" @@ -50,7 +50,7 @@ type invoke struct { // success sends the response payload for an in-progress invocation. // Notes: -// * An invoke is not complete until next() is called again! +// - An invoke is not complete until next() is called again! func (i *invoke) success(payload []byte, contentType string) error { url := i.client.baseURL + i.id + "/response" return i.client.post(url, payload, contentType) @@ -58,9 +58,9 @@ func (i *invoke) success(payload []byte, contentType string) error { // failure sends the payload to the Runtime API. This marks the function's invoke as a failure. // Notes: -// * The execution of the function process continues, and is billed, until next() is called again! -// * A Lambda Function continues to be re-used for future invokes even after a failure. -// If the error is fatal (panic, unrecoverable state), exit the process immediately after calling failure() +// - The execution of the function process continues, and is billed, until next() is called again! +// - A Lambda Function continues to be re-used for future invokes even after a failure. +// If the error is fatal (panic, unrecoverable state), exit the process immediately after calling failure() func (i *invoke) failure(payload []byte, contentType string) error { url := i.client.baseURL + i.id + "/error" return i.client.post(url, payload, contentType) diff --git a/lambda/runtime_api_client_test.go b/lambda/runtime_api_client_test.go index 2e95ed07..4693048b 100644 --- a/lambda/runtime_api_client_test.go +++ b/lambda/runtime_api_client_test.go @@ -4,7 +4,7 @@ package lambda import ( "fmt" - "io/ioutil" + "io/ioutil" //nolint: staticcheck "net/http" "net/http/httptest" "strings" diff --git a/lambda/sigterm_test.go b/lambda/sigterm_test.go index 195c9550..886a6d72 100644 --- a/lambda/sigterm_test.go +++ b/lambda/sigterm_test.go @@ -4,7 +4,7 @@ package lambda import ( - "io/ioutil" + "io/ioutil" //nolint: staticcheck "net/http" "os" "os/exec"