Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvements to golint #243

Merged
merged 6 commits into from
Oct 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions events/apigw.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ type APIGatewayCustomAuthorizerPolicy struct {
Statement []IAMPolicyStatement
}

// IAMPolicyStatement represents one statement from IAM policy with action, effect and resource
type IAMPolicyStatement struct {
Action []string
Effect string
Expand Down
2 changes: 1 addition & 1 deletion events/cloudwatch_logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ type CloudwatchLogsData struct {
LogEvents []CloudwatchLogsLogEvent `json:"logEvents"`
}

// LogEvent represents a log entry from cloudwatch logs
// CloudwatchLogsLogEvent represents a log entry from cloudwatch logs
type CloudwatchLogsLogEvent struct {
ID string `json:"id"`
Timestamp int64 `json:"timestamp"`
Expand Down
2 changes: 1 addition & 1 deletion events/code_commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (t *CodeCommitEventTime) UnmarshalJSON(data []byte) error {
return err
}

// represents a CodeCommit record
// CodeCommitRecord represents a CodeCommit record
type CodeCommitRecord struct {
EventID string `json:"eventId"`
EventVersion string `json:"eventVersion"`
Expand Down
13 changes: 13 additions & 0 deletions events/codebuild.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const (
CodeBuildPhaseChangeDetailType = "CodeBuild Build Phase Change"
)

// CodeBuildPhaseStatus represents the status of code build phase (i.e. failed, in progress)
type CodeBuildPhaseStatus string

const (
Expand All @@ -23,6 +24,7 @@ const (
CodeBuildPhaseStatusTimedOut = "TIMED_OUT"
)

// CodeBuildPhaseType represents the type of the code build phase (i.e. submitted, install)
type CodeBuildPhaseType string

const (
Expand Down Expand Up @@ -73,6 +75,7 @@ type CodeBuildEvent struct {
Detail CodeBuildEventDetail `json:"detail"`
}

// CodeBuildEventDetail represents the all details related to the code build event
type CodeBuildEventDetail struct {
BuildStatus CodeBuildPhaseStatus `json:"build-status"`
ProjectName string `json:"project-name"`
Expand All @@ -90,6 +93,7 @@ type CodeBuildEventDetail struct {
CompletedPhaseEnd CodeBuildTime `json:"completed-phase-end"`
}

//CodeBuildEventAdditionalInformation represents additional informations to the code build event
type CodeBuildEventAdditionalInformation struct {
Artifact CodeBuildArtifact `json:"artifact"`

Expand All @@ -110,12 +114,14 @@ type CodeBuildEventAdditionalInformation struct {
Phases []CodeBuildPhase `json:"phases"`
}

// CodeBuildArtifact represents the artifact provided to build
type CodeBuildArtifact struct {
MD5Sum string `json:"md5sum"`
SHA256Sum string `json:"sha256sum"`
Location string `json:"location"`
}

// CodeBuildEnvironment represents the environment for a build
type CodeBuildEnvironment struct {
Image string `json:"image"`
PrivilegedMode bool `json:"privileged-mode"`
Expand All @@ -124,6 +130,7 @@ type CodeBuildEnvironment struct {
EnvironmentVariables []CodeBuildEnvironmentVariable `json:"environment-variables"`
}

// CodeBuildEnvironmentVariable encapsulate environment variables for the code build
type CodeBuildEnvironmentVariable struct {
// Name is the name of the environment variable.
Name string `json:"name"`
Expand All @@ -135,17 +142,20 @@ type CodeBuildEnvironmentVariable struct {
Value string `json:"value"`
}

// CodeBuildSource represent the code source will be build
type CodeBuildSource struct {
Location string `json:"location"`
Type string `json:"type"`
}

// CodeBuildLogs gives the log details of a code build
type CodeBuildLogs struct {
GroupName string `json:"group-name"`
StreamName string `json:"stream-name"`
DeepLink string `json:"deep-link"`
}

// CodeBuildPhase represents the phase of a build and its details
type CodeBuildPhase struct {
PhaseContext []interface{} `json:"phase-context"`

Expand All @@ -160,14 +170,17 @@ type CodeBuildPhase struct {
PhaseStatus CodeBuildPhaseStatus `json:"phase-status"`
}

// CodeBuildTime represents the time of the build
type CodeBuildTime time.Time

const codeBuildTimeFormat = "Jan 2, 2006 3:04:05 PM"

// MarshalJSON converts a given CodeBuildTime to json
func (t CodeBuildTime) MarshalJSON() ([]byte, error) {
return json.Marshal(time.Time(t).Format(codeBuildTimeFormat))
}

// UnmarshalJSON converts a given json to a CodeBuildTime
func (t *CodeBuildTime) UnmarshalJSON(data []byte) error {
var s string
if err := json.Unmarshal(data, &s); err != nil {
Expand Down
4 changes: 4 additions & 0 deletions events/duration.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

type DurationSeconds time.Duration

// UnmarshalJSON converts a given json to a DurationSeconds
func (duration *DurationSeconds) UnmarshalJSON(data []byte) error {
var seconds float64
if err := json.Unmarshal(data, &seconds); err != nil {
Expand All @@ -18,13 +19,15 @@ func (duration *DurationSeconds) UnmarshalJSON(data []byte) error {
return nil
}

// MarshalJSON converts a given DurationSeconds to json
func (duration DurationSeconds) MarshalJSON() ([]byte, error) {
seconds := time.Duration(duration).Seconds()
return json.Marshal(int64(math.Ceil(seconds)))
}

type DurationMinutes time.Duration

// UnmarshalJSON converts a given json to a DurationMinutes
func (duration *DurationMinutes) UnmarshalJSON(data []byte) error {
var minutes float64
if err := json.Unmarshal(data, &minutes); err != nil {
Expand All @@ -35,6 +38,7 @@ func (duration *DurationMinutes) UnmarshalJSON(data []byte) error {
return nil
}

// MarshalJSON converts a given DurationMinutes to json
func (duration DurationMinutes) MarshalJSON() ([]byte, error) {
minutes := time.Duration(duration).Minutes()
return json.Marshal(int64(math.Ceil(minutes)))
Expand Down
2 changes: 1 addition & 1 deletion events/dynamodb.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ type DynamoDBUserIdentity struct {
PrincipalID string `json:"principalId"`
}

// A description of a single data modification that was performed on an item
// DynamoDBStreamRecord represents a description of a single data modification that was performed on an item
// in a DynamoDB table.
type DynamoDBStreamRecord struct {

Expand Down
2 changes: 2 additions & 0 deletions events/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ import (
"time"
)

// S3Event which wrap an array of S3EventRecord
type S3Event struct {
Records []S3EventRecord `json:"Records"`
}

// S3EventRecord which wrap record data
type S3EventRecord struct {
EventVersion string `json:"eventVersion"`
EventSource string `json:"eventSource"`
Expand Down
5 changes: 5 additions & 0 deletions events/s3_batch_job.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,36 @@

package events

// S3BatchJobEvent encapsulates the detail of a s3 batch job
type S3BatchJobEvent struct {
InvocationSchemaVersion string `json:"invocationSchemaVersion"`
InvocationID string `json:"invocationId"`
Job S3BatchJob `json:"job"`
Tasks []S3BatchJobTask `json:"tasks"`
}

// S3BatchJob whichs have the job id
type S3BatchJob struct {
ID string `json:"id"`
}

// S3BatchJobTask represents one task in the s3 batch job and have all task details
type S3BatchJobTask struct {
TaskID string `json:"taskId"`
S3Key string `json:"s3Key"`
S3VersionID string `json:"s3VersionId"`
S3BucketARN string `json:"s3BucketArn"`
}

// S3BatchJobResponse is the response of a iven s3 batch job with the results
type S3BatchJobResponse struct {
InvocationSchemaVersion string `json:"invocationSchemaVersion"`
TreatMissingKeysAs string `json:"treatMissingKeysAs"`
InvocationID string `json:"invocationId"`
Results []S3BatchJobResult `json:"results"`
}

// S3BatchJobResult represents the result of a given task
type S3BatchJobResult struct {
TaskID string `json:"taskId"`
ResultCode string `json:"resultCode"`
Expand Down
2 changes: 1 addition & 1 deletion events/test/jsoncompare.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/stretchr/testify/assert"
)

// Asserts two JSON files are semantically equal
// AssertJsonsEqual asserts two JSON files are semantically equal
// (ignores white-space and attribute order)
func AssertJsonsEqual(t *testing.T, expectedJson []byte, actualJson []byte) {
assert.JSONEq(t, string(expectedJson), string(actualJson))
Expand Down
1 change: 1 addition & 0 deletions events/test/readjson.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"testing"
)

// ReadJSONFromFile reads a given input file to JSON
func ReadJSONFromFile(t *testing.T, inputFile string) []byte {
inputJSON, err := ioutil.ReadFile(inputFile)
if err != nil {
Expand Down
4 changes: 4 additions & 0 deletions lambda/function.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,23 @@ import (
"github.com/aws/aws-lambda-go/lambdacontext"
)

// Function struct which wrap the Handler
type Function struct {
handler Handler
}

// NewFunction which creates a Function with a given Handler
func NewFunction(handler Handler) *Function {
return &Function{handler: handler}
}

// Ping method which given a PingRequest and a PingResponse parses the PingResponse
func (fn *Function) Ping(req *messages.PingRequest, response *messages.PingResponse) error {
*response = messages.PingResponse{}
return nil
}

// Invoke method try to perform a command given an InvokeRequest and an InvokeResponse
func (fn *Function) Invoke(req *messages.InvokeRequest, response *messages.InvokeResponse) error {
defer func() {
if err := recover(); err != nil {
Expand Down