diff --git a/cmd/build-lambda-zip/main.go b/cmd/build-lambda-zip/main.go index 910e76ac..88482a2e 100644 --- a/cmd/build-lambda-zip/main.go +++ b/cmd/build-lambda-zip/main.go @@ -25,7 +25,7 @@ func main() { app.Action = func(c *cli.Context) error { if !c.Args().Present() { - return errors.New("No input provided") + return errors.New("no input provided") } inputExe := c.Args().First() @@ -35,7 +35,7 @@ func main() { } if err := compressExeAndArgs(outputZip, inputExe, c.Args().Tail()); err != nil { - return fmt.Errorf("Failed to compress file: %v", err) + return fmt.Errorf("failed to compress file: %v", err) } return nil } @@ -71,7 +71,6 @@ func compressExeAndArgs(outZipPath string, exePath string, args []string) error if closeErr != nil { fmt.Fprintf(os.Stderr, "Failed to close zip file: %v\n", closeErr) } - return }() zipWriter := zip.NewWriter(zipFile) diff --git a/events/attributevalue_test.go b/events/attributevalue_test.go index 5bb63f32..2246b4d4 100644 --- a/events/attributevalue_test.go +++ b/events/attributevalue_test.go @@ -259,9 +259,9 @@ func Test_DynamoDBAttributeValue_NewAttribute(t *testing.T) { assert.Equal(t, true, av.Boolean()) } { - av := NewBinarySetAttribute([][]byte{[]byte{1, 2, 3}}) + av := NewBinarySetAttribute([][]byte{{1, 2, 3}}) assert.Equal(t, DataTypeBinarySet, av.DataType()) - assert.Equal(t, [][]byte{[]byte{1, 2, 3}}, av.BinarySet()) + assert.Equal(t, [][]byte{{1, 2, 3}}, av.BinarySet()) } { av := NewListAttribute([]DynamoDBAttributeValue{ diff --git a/events/cloudwatch_logs.go b/events/cloudwatch_logs.go index 9f84fe5f..bc7bbf8a 100644 --- a/events/cloudwatch_logs.go +++ b/events/cloudwatch_logs.go @@ -26,15 +26,14 @@ func (c CloudwatchLogsRawData) Parse() (d CloudwatchLogsData, err error) { } zr, err := gzip.NewReader(bytes.NewBuffer(data)) - defer zr.Close() if err != nil { return } + defer zr.Close() - buf := &bytes.Buffer{} - buf.ReadFrom(zr) + dec := json.NewDecoder(zr) + err = dec.Decode(&d) - err = json.Unmarshal(buf.Bytes(), &d) return } diff --git a/events/cognito.go b/events/cognito.go index 5124f0dc..be24c887 100644 --- a/events/cognito.go +++ b/events/cognito.go @@ -37,7 +37,7 @@ type CognitoEventUserPoolsPostConfirmation struct { } // CognitoEventUserPoolsPreTokenGen is sent by AWS Cognito User Pools when a user attempts to retrieve -// credentials, allowing a Lambda to perform insert, supress or override claims +// credentials, allowing a Lambda to perform insert, suppress or override claims type CognitoEventUserPoolsPreTokenGen struct { CognitoEventUserPoolsHeader Request CognitoEventUserPoolsPreTokenGenRequest `json:"request"` @@ -133,7 +133,7 @@ type CognitoEventUserPoolsMigrateUserResponse struct { ForceAliasCreation bool `json:"forceAliasCreation"` } -// ClaimsOverrideDetails allows lambda to add, supress or override claims in the token +// ClaimsOverrideDetails allows lambda to add, suppress or override claims in the token type ClaimsOverrideDetails struct { GroupOverrideDetails GroupConfiguration `json:"groupOverrideDetails"` ClaimsToAddOrOverride map[string]string `json:"claimsToAddOrOverride"` diff --git a/events/firehose_test.go b/events/firehose_test.go index 0aef155d..34c9d146 100644 --- a/events/firehose_test.go +++ b/events/firehose_test.go @@ -20,7 +20,6 @@ func testFirehoseResponseMarshaling(t *testing.T) { } func testMarshaling(t *testing.T, jsonFile string) { - // 1. read JSON from file inputJson := test.ReadJSONFromFile(t, jsonFile) @@ -41,7 +40,6 @@ func testMarshaling(t *testing.T, jsonFile string) { } func TestSampleTransformation(t *testing.T) { - inputJson := test.ReadJSONFromFile(t, "./testdata/kinesis-firehose-event.json") // de-serialize into Go object diff --git a/lambda/handler.go b/lambda/handler.go index 96eeac2e..f6f931c1 100644 --- a/lambda/handler.go +++ b/lambda/handler.go @@ -58,17 +58,20 @@ func validateArguments(handler reflect.Type) (bool, error) { func validateReturns(handler reflect.Type) error { errorType := reflect.TypeOf((*error)(nil)).Elem() - if handler.NumOut() > 2 { + + switch n := handler.NumOut(); { + case n > 2: return fmt.Errorf("handler may not return more than two values") - } else if handler.NumOut() > 1 { + case n > 1: if !handler.Out(1).Implements(errorType) { return fmt.Errorf("handler returns two values, but the second does not implement error") } - } else if handler.NumOut() == 1 { + case n == 1: if !handler.Out(0).Implements(errorType) { return fmt.Errorf("handler returns a single value, but it does not implement error") } } + return nil }