From a626496c5ae05d06bfff3f04ae42f3a81de78ef9 Mon Sep 17 00:00:00 2001 From: Jens Willemsens <6514515+JenswBE@users.noreply.github.com> Date: Thu, 2 Feb 2023 20:09:20 +0100 Subject: [PATCH] Use common linting config --- .github/workflows/test-build-publish.yml | 8 ++--- .golangci.yml | 21 ------------ internal/manager.go | 41 +++++++++++++----------- lint.sh | 3 ++ 4 files changed, 28 insertions(+), 45 deletions(-) delete mode 100644 .golangci.yml create mode 100644 lint.sh diff --git a/.github/workflows/test-build-publish.yml b/.github/workflows/test-build-publish.yml index f7bc789..4834e9f 100644 --- a/.github/workflows/test-build-publish.yml +++ b/.github/workflows/test-build-publish.yml @@ -35,16 +35,14 @@ jobs: check-latest: true go-version: ${{ env.GO_VERSION }} + - name: Pull common linter configs + run: wget -O .golangci.yml https://raw.githubusercontent.com/JenswBE/setup/main/programming_configs/golang/.golangci.yml + - name: golangci-lint uses: golangci/golangci-lint-action@v3 with: version: latest - - name: Run exhaustive - run: | - go install github.com/nishanths/exhaustive/...@latest - exhaustive ./... - - name: Start E2E services working-directory: e2e run: | diff --git a/.golangci.yml b/.golangci.yml deleted file mode 100644 index 9ef105a..0000000 --- a/.golangci.yml +++ /dev/null @@ -1,21 +0,0 @@ -linters: - presets: - - bugs - - format - - performance - - style - - disable: - - exhaustivestruct - - exhaustruct - - gci - - gochecknoglobals - - golint - - ifshort - - interfacer - - maligned - - nlreturn - - nosnakecase - - scopelint - - varnamelen - - wsl diff --git a/internal/manager.go b/internal/manager.go index 2e4feca..b6235dd 100644 --- a/internal/manager.go +++ b/internal/manager.go @@ -143,27 +143,30 @@ func (m *Manager) Run(ctx context.Context, c *config.Config) map[string]report.R } func pingHealthCheckURL(ctx context.Context, u *url.URL) { - if u != nil { - // Create request - logger := log.With().Str("health_check_url", u.String()).Logger() - req, err := http.NewRequestWithContext(ctx, http.MethodGet, u.String(), nil) - if err != nil { - logger.Error().Err(err).Msg("Failed to create request for health check URL") - return - } + // Skip if URL is nil + if u == nil { + return + } - // Call health check - resp, err := http.DefaultClient.Do(req) - if err != nil { - logger.Error().Err(err).Msg("Failed to send GET request to health check URL") - return - } + // Create request + logger := log.With().Str("health_check_url", u.String()).Logger() + req, err := http.NewRequestWithContext(ctx, http.MethodGet, u.String(), nil) + if err != nil { + logger.Error().Err(err).Msg("Failed to create request for health check URL") + return + } - // Close body - if resp != nil { - if err = resp.Body.Close(); err != nil { - log.Error().Err(err).Msg("Failed to close response body after calling health check URL") - } + // Call health check + resp, err := http.DefaultClient.Do(req) + if err != nil { + logger.Error().Err(err).Msg("Failed to send GET request to health check URL") + return + } + + // Close body + if resp != nil { + if err = resp.Body.Close(); err != nil { + log.Error().Err(err).Msg("Failed to close response body after calling health check URL") } } } diff --git a/lint.sh b/lint.sh new file mode 100644 index 0000000..9ca5f95 --- /dev/null +++ b/lint.sh @@ -0,0 +1,3 @@ +# This script is intended to be sourced like "source lint.sh" or ". lint.sh". +# Config is available at https://raw.githubusercontent.com/JenswBE/setup/main/programming_configs/golang/.golangci.yml +golangci-lint run -c ../setup/programming_configs/golang/.golangci.yml