From 1181deb197819a570e295890ec817b5823e37a27 Mon Sep 17 00:00:00 2001 From: Enrico Stahn Date: Sun, 22 Nov 2020 11:15:40 +1100 Subject: [PATCH] chore: golang 1.15 / golangci-lint action (#127) --- .github/stale.yml | 1 - .github/workflows/release.yml | 2 +- .github/workflows/test.yml | 17 ++++++++--------- .pre-commit-config.yaml | 21 +++++++++++++++++++++ cmd/server.go | 3 --- phpfpm/exporter.go | 3 ++- phpfpm/phpfpm.go | 2 +- 7 files changed, 33 insertions(+), 16 deletions(-) create mode 100644 .pre-commit-config.yaml diff --git a/.github/stale.yml b/.github/stale.yml index 968126a..f761b3d 100644 --- a/.github/stale.yml +++ b/.github/stale.yml @@ -17,4 +17,3 @@ markComment: > for your contributions. # Comment to post when closing a stale issue. Set to `false` to disable closeComment: false - diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 633982d..57c70cc 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -38,7 +38,7 @@ jobs: - name: Set up Go uses: actions/setup-go@v2.1.3 with: - go-version: 1.14 + go-version: ^1.15.0 id: go - name: Login to DockerHub diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 05cca2f..3cae6e3 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -23,21 +23,20 @@ jobs: - name: Checkout uses: actions/checkout@v2 - - name: Install golangci-lint - run: curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.23.7 - - - name: Lint - run: $(go env GOPATH)/bin/golangci-lint run + - name: golangci-lint + uses: golangci/golangci-lint-action@v2 + with: + version: v1.32 test: name: Test runs-on: ubuntu-latest steps: - - name: Set up Go 1.14 + - name: Setup Go uses: actions/setup-go@v2.1.3 with: - go-version: 1.14 + go-version: ^1.15.0 id: go - name: Checkout @@ -62,10 +61,10 @@ jobs: - name: Unshallow run: git fetch --prune --unshallow - - name: Set up Go + - name: Setup Go uses: actions/setup-go@v2.1.3 with: - go-version: 1.14 + go-version: ^1.15.0 id: go - name: Run GoReleaser diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..4411282 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,21 @@ +repos: +- repo: https://github.com/pre-commit/pre-commit-hooks + rev: v3.3.0 + hooks: + - id: trailing-whitespace + - id: check-added-large-files + - id: check-json + - id: pretty-format-json + args: ['--autofix'] + - id: check-merge-conflict + - id: check-symlinks + - id: check-yaml + - id: detect-private-key + - id: check-merge-conflict + - id: check-executables-have-shebangs + - id: end-of-file-fixer + - id: mixed-line-ending +- repo: https://github.com/golangci/golangci-lint + rev: v1.32.2 + hooks: + - id: golangci-lint diff --git a/cmd/server.go b/cmd/server.go index bc638d8..6778f03 100644 --- a/cmd/server.go +++ b/cmd/server.go @@ -126,9 +126,6 @@ func init() { serverCmd.Flags().StringSliceVar(&scrapeURIs, "phpfpm.scrape-uri", []string{"tcp://127.0.0.1:9000/status"}, "FastCGI address, e.g. unix:///tmp/php.sock;/status or tcp://127.0.0.1:9000/status") serverCmd.Flags().BoolVar(&fixProcessCount, "phpfpm.fix-process-count", false, "Enable to calculate process numbers via php-fpm_exporter since PHP-FPM sporadically reports wrong active/idle/total process numbers.") - //viper.BindEnv("web.listen-address", "PHP_FPM_WEB_LISTEN_ADDRESS") - //viper.BindPFlag("web.listen-address", serverCmd.Flags().Lookup("web.listen-address")) - // Workaround since vipers BindEnv is currently not working as expected (see https://github.com/spf13/viper/issues/461) envs := map[string]string{ diff --git a/phpfpm/exporter.go b/phpfpm/exporter.go index b15df46..25785c7 100644 --- a/phpfpm/exporter.go +++ b/phpfpm/exporter.go @@ -15,8 +15,9 @@ package phpfpm import ( - "sync" "fmt" + "sync" + "github.com/prometheus/client_golang/prometheus" ) diff --git a/phpfpm/phpfpm.go b/phpfpm/phpfpm.go index ad27fa0..1e1c8c1 100644 --- a/phpfpm/phpfpm.go +++ b/phpfpm/phpfpm.go @@ -213,7 +213,7 @@ func JSONResponseFixer(content []byte) []byte { sold := match[0] snew := match[1] + string(requestURI) + match[3] - c = strings.Replace(c, sold, snew, -1) + c = strings.ReplaceAll(c, sold, snew) } return []byte(c)