diff --git a/.golangci.yml b/.golangci.yml index b38e90e..e51350f 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -5,30 +5,51 @@ linters: - asciicheck - bidichk - bodyclose + - containedctx - contextcheck - - deadcode - durationcheck - errcheck + - errchkjson - errname - errorlint + - exhaustive - exportloopref - - forcetypeassert + - gocheckcompilerdirectives - gocyclo - godot - - gofmt + - gofumpt - gosec - gosimple + - gosmopolitan - govet - - ifshort + - importas - ineffassign + - makezero + - mirror - misspell + - nilerr + - nilnil + - noctx + - nosprintfhostport + - predeclared + - reassign + - revive - staticcheck + - tenv + - testableexamples - typecheck - unconvert - unused - - varcheck + - usestdlibvars - wastedassign - whitespace linters-settings: misspell: locale: US + usestdlibvars: + crypto-hash: true + http-method: false + os-dev-null: true + sql-isolation-level: true + time-layout: true + tls-signature-scheme: true diff --git a/Makefile b/Makefile index 48dfd09..fa899f9 100644 --- a/Makefile +++ b/Makefile @@ -14,9 +14,9 @@ GOVVV = $(GOBIN)/govvv MOCKGEN = $(GOBIN)/mockgen PIGEON = $(GOBIN)/pigeon -GOLANGCI_LINT_VERSION := v1.43.0 -GOLANGCI_LINT_INSTALLATION_SHA256 := 294771225087ee48c8e0a45a99ac82ed8f9c6e9d384e692ab201986479c8594f -GOLANGCI_LINT_BINARY_SHA256 := c6f662fd533a7bff89c2d554dbe0708b6d3925f4b305d3522591d6bca0b48469 +GOLANGCI_LINT_VERSION := v1.53.3 +GOLANGCI_LINT_INSTALLATION_SHA256 := 060f1f3deb31b3d3b9515d691d9a776354cd63c7fcb5e036f18f0444cf2c934b +GOLANGCI_LINT_BINARY_SHA256 := 09237052ea9582630019182e890288ec155567fc949e6f329e3beb2c6e76b1b5 .PHONY: all all: test build start diff --git a/cmd/goer/main.go b/cmd/goer/main.go index dd6bf5c..cbb0877 100644 --- a/cmd/goer/main.go +++ b/cmd/goer/main.go @@ -6,7 +6,7 @@ // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // -// http://www.apache.org/licenses/LICENSE-2.0 +// http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, diff --git a/internal/config/config.go b/internal/config/config.go index 718e6fd..470f095 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -6,7 +6,7 @@ // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // -// http://www.apache.org/licenses/LICENSE-2.0 +// http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, diff --git a/internal/config/config_test.go b/internal/config/config_test.go index ac458be..3bfa8c9 100644 --- a/internal/config/config_test.go +++ b/internal/config/config_test.go @@ -6,7 +6,7 @@ // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // -// http://www.apache.org/licenses/LICENSE-2.0 +// http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, diff --git a/internal/database/database.go b/internal/database/database.go index 829e075..cbcd8fc 100644 --- a/internal/database/database.go +++ b/internal/database/database.go @@ -6,7 +6,7 @@ // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // -// http://www.apache.org/licenses/LICENSE-2.0 +// http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, diff --git a/internal/database/database_test.go b/internal/database/database_test.go index 5e6a2b7..8160f78 100644 --- a/internal/database/database_test.go +++ b/internal/database/database_test.go @@ -6,7 +6,7 @@ // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // -// http://www.apache.org/licenses/LICENSE-2.0 +// http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, diff --git a/internal/database/drivers/drivers.go b/internal/database/drivers/drivers.go index 8e10caf..6984a86 100644 --- a/internal/database/drivers/drivers.go +++ b/internal/database/drivers/drivers.go @@ -6,7 +6,7 @@ // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // -// http://www.apache.org/licenses/LICENSE-2.0 +// http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, diff --git a/internal/database/drivers/mongodb/mongodb.go b/internal/database/drivers/mongodb/mongodb.go index f9ee6af..4aeab29 100644 --- a/internal/database/drivers/mongodb/mongodb.go +++ b/internal/database/drivers/mongodb/mongodb.go @@ -6,7 +6,7 @@ // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // -// http://www.apache.org/licenses/LICENSE-2.0 +// http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, @@ -180,7 +180,6 @@ func (m *Database) GetEvents(ctx context.Context, request requests.MultipleEvent SetSkip(int64((request.PageNo-1)*request.PageSize)). SetLimit(int64(limit)), ) - if err != nil { continue } @@ -201,7 +200,7 @@ func (m *Database) GetEvents(ctx context.Context, request requests.MultipleEvent } // UpstreamDownstreamSearch searches for events upstream and/or downstream of event by ID. -func (m *Database) UpstreamDownstreamSearch(ctx context.Context, id string) ([]drivers.EiffelEvent, error) { +func (m *Database) UpstreamDownstreamSearch(_ context.Context, _ string) ([]drivers.EiffelEvent, error) { return nil, errors.New("not yet implemented") } @@ -220,9 +219,8 @@ func (m *Database) GetEventByID(ctx context.Context, id string) (drivers.EiffelE err := singleResult.Decode(&event) if err != nil { continue - } else { - return drivers.EiffelEvent(event), nil } + return drivers.EiffelEvent(event), nil } return nil, fmt.Errorf("%q not found in any collection", id) } diff --git a/internal/logger/logger.go b/internal/logger/logger.go index c5ce3a5..ff08fa1 100644 --- a/internal/logger/logger.go +++ b/internal/logger/logger.go @@ -6,7 +6,7 @@ // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // -// http://www.apache.org/licenses/LICENSE-2.0 +// http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, diff --git a/internal/responses/responses.go b/internal/responses/responses.go index 2f0be65..2be3fe5 100644 --- a/internal/responses/responses.go +++ b/internal/responses/responses.go @@ -6,7 +6,7 @@ // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // -// http://www.apache.org/licenses/LICENSE-2.0 +// http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, @@ -22,7 +22,7 @@ import ( // RespondWithJSON writes a JSON response with a status code to the HTTP ResponseWriter. func RespondWithJSON(w http.ResponseWriter, code int, payload interface{}) { - response, _ := json.Marshal(payload) + response, _ := json.Marshal(payload) //nolint:errchkjson w.Header().Set("Content-Type", "application/json") w.WriteHeader(code) diff --git a/internal/responses/responses_test.go b/internal/responses/responses_test.go index d47bce4..dbe7c2f 100644 --- a/internal/responses/responses_test.go +++ b/internal/responses/responses_test.go @@ -6,7 +6,7 @@ // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // -// http://www.apache.org/licenses/LICENSE-2.0 +// http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, @@ -27,7 +27,7 @@ func TestRespondWithJSON(t *testing.T) { responseRecorder := httptest.NewRecorder() RespondWithJSON(responseRecorder, 200, map[string]string{"hello": "world"}) assert.Equal(t, "application/json", responseRecorder.Header().Get("Content-Type")) - assert.Equal(t, 200, responseRecorder.Result().StatusCode) + assert.Equal(t, 200, responseRecorder.Result().StatusCode) //nolint:bodyclose assert.JSONEq(t, `{"hello": "world"}`, responseRecorder.Body.String()) } @@ -35,6 +35,6 @@ func TestRespondWithJSON(t *testing.T) { func TestRespondWithError(t *testing.T) { responseRecorder := httptest.NewRecorder() RespondWithError(responseRecorder, 400, "Bad Request") - assert.Equal(t, 400, responseRecorder.Result().StatusCode) + assert.Equal(t, 400, responseRecorder.Result().StatusCode) //nolint:bodyclose assert.Equal(t, "Bad Request", responseRecorder.Body.String()) } diff --git a/pkg/application/application.go b/pkg/application/application.go index 6dcb5d3..a789c2d 100644 --- a/pkg/application/application.go +++ b/pkg/application/application.go @@ -6,7 +6,7 @@ // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // -// http://www.apache.org/licenses/LICENSE-2.0 +// http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, diff --git a/pkg/application/application_test.go b/pkg/application/application_test.go index 4350e01..dc17a09 100644 --- a/pkg/application/application_test.go +++ b/pkg/application/application_test.go @@ -6,7 +6,7 @@ // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // -// http://www.apache.org/licenses/LICENSE-2.0 +// http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, diff --git a/pkg/server/server.go b/pkg/server/server.go index ab17e95..870dcfd 100644 --- a/pkg/server/server.go +++ b/pkg/server/server.go @@ -6,7 +6,7 @@ // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // -// http://www.apache.org/licenses/LICENSE-2.0 +// http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, @@ -19,6 +19,7 @@ import ( "errors" "log" "net/http" + "time" "github.com/gorilla/mux" ) @@ -44,7 +45,9 @@ type WebServer struct { // Create a new WebServer. func Get() Server { return &WebServer{ - server: &http.Server{}, + server: &http.Server{ + ReadTimeout: 10 * time.Second, + }, running: make(chan bool, 2), // Buffer up to two messages. stopped: make(chan bool, 2), // Buffer up to two messages. } diff --git a/pkg/server/server_test.go b/pkg/server/server_test.go index 74a196e..88f5427 100644 --- a/pkg/server/server_test.go +++ b/pkg/server/server_test.go @@ -6,7 +6,7 @@ // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // -// http://www.apache.org/licenses/LICENSE-2.0 +// http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, diff --git a/pkg/v1/api/api.go b/pkg/v1/api/api.go index 5fc7f1f..123bcb6 100644 --- a/pkg/v1/api/api.go +++ b/pkg/v1/api/api.go @@ -6,7 +6,7 @@ // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // -// http://www.apache.org/licenses/LICENSE-2.0 +// http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, diff --git a/pkg/v1/handlers/events/events.go b/pkg/v1/handlers/events/events.go index 69d28e5..88223f5 100644 --- a/pkg/v1/handlers/events/events.go +++ b/pkg/v1/handlers/events/events.go @@ -6,7 +6,7 @@ // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // -// http://www.apache.org/licenses/LICENSE-2.0 +// http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, diff --git a/pkg/v1/handlers/events/events_test.go b/pkg/v1/handlers/events/events_test.go index f449800..34fc40d 100644 --- a/pkg/v1/handlers/events/events_test.go +++ b/pkg/v1/handlers/events/events_test.go @@ -6,7 +6,7 @@ // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // -// http://www.apache.org/licenses/LICENSE-2.0 +// http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, diff --git a/pkg/v1/handlers/search/search.go b/pkg/v1/handlers/search/search.go index 24b938b..85203fc 100644 --- a/pkg/v1/handlers/search/search.go +++ b/pkg/v1/handlers/search/search.go @@ -6,7 +6,7 @@ // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // -// http://www.apache.org/licenses/LICENSE-2.0 +// http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, @@ -25,21 +25,21 @@ import ( "github.com/eiffel-community/eiffel-goer/internal/responses" ) -type SearchHandler struct { +type Handler struct { Config config.Config Database drivers.Database Logger *log.Entry } // Get a new handler for the search endpoint. -func Get(cfg config.Config, db drivers.Database, logger *log.Entry) *SearchHandler { - return &SearchHandler{ +func Get(cfg config.Config, db drivers.Database, logger *log.Entry) *Handler { + return &Handler{ cfg, db, logger, } } // UpstreamDownstream handles POST requests against the /search/{id} endpoint. // To get upstream/downstream events for an event based on the searchParameters passed. -func (h *SearchHandler) UpstreamDownstream(w http.ResponseWriter, r *http.Request) { +func (h *Handler) UpstreamDownstream(w http.ResponseWriter, _ *http.Request) { responses.RespondWithError(w, http.StatusNotImplemented, http.StatusText(http.StatusNotImplemented)) } diff --git a/pkg/v1/handlers/search/test_search.go b/pkg/v1/handlers/search/test_search.go index e742d3d..aa2c429 100644 --- a/pkg/v1/handlers/search/test_search.go +++ b/pkg/v1/handlers/search/test_search.go @@ -6,7 +6,7 @@ // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // -// http://www.apache.org/licenses/LICENSE-2.0 +// http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS,