diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..18191d1 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,51 @@ +name: Go CI + +on: + push: + branches: + - main + pull_request: + workflow_dispatch: + +permissions: + contents: read + +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true + +jobs: + test: + name: Go ${{ matrix.go-version }} + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + go-version: ["stable", "oldstable"] + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + - uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0 + with: + go-version: ${{ matrix.go-version }} + check-latest: true + - name: Check formatting + run: | + unformatted="$(gofmt -l .)" + if [ -n "$unformatted" ]; then + printf 'Run gofmt on:\n%s\n' "$unformatted" + exit 1 + fi + - name: Check module tidiness + if: matrix.go-version == 'stable' + run: go mod tidy -diff + - name: Test + run: go test -race -timeout=10s ./... + - name: Vet + run: go vet ./... + - name: Build + run: go build ./... + - name: Lint + if: matrix.go-version == 'stable' + uses: golangci/golangci-lint-action@ba0d7d2ec06a0ea1cb5fa41b2e4a3ab91d21278a # v9.3.0 + with: + version: v2.15.0 diff --git a/.github/workflows/lint-pr-title.yml b/.github/workflows/lint-pr-title.yml new file mode 100644 index 0000000..1493a93 --- /dev/null +++ b/.github/workflows/lint-pr-title.yml @@ -0,0 +1,36 @@ +name: Lint PR Title + +on: + pull_request: + types: + - opened + - reopened + - edited + - synchronize + +permissions: + pull-requests: read + +jobs: + lint: + runs-on: ubuntu-latest + steps: + - uses: amannn/action-semantic-pull-request@48f256284bd46cdaab1048c3721360e808335d50 # v6.1.1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + types: | + feat + fix + docs + style + refactor + perf + test + build + ci + chore + revert + security + subjectPattern: '^[a-z].+$' + subjectPatternError: 'The description must start with a lowercase letter.' diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 8670c48..0000000 --- a/.travis.yml +++ /dev/null @@ -1,12 +0,0 @@ -language: go - -go: - - 1.x - - master - -install: - - curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(go env GOPATH)/bin v1.23.6 - -script: - - go test -v -race -timeout=10s ./... - - golangci-lint run diff --git a/README.md b/README.md index 3afc3d5..d1e8ba6 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,13 @@ This is a fork of a [dead statsd client project](https://github.com/alexcesaro/s ## Download - go get github.com/multiplay/statsd + go get github.com/rocketsciencegg/statsd/v2 + +Import the v2 module in your Go code: + +```go +import "github.com/rocketsciencegg/statsd/v2" +``` ## License diff --git a/doc.go b/doc.go index bb7b986..0489876 100644 --- a/doc.go +++ b/doc.go @@ -1,8 +1,7 @@ /* Package statsd is a simple and efficient StatsD client. - -Options +# Options Use options to configure the Client: target host/port, sampling rate, tags, etc. @@ -12,13 +11,12 @@ rate), you should use the Clone() method of the Client. Because when cloning a Client, the same connection is reused so this is way cheaper and more efficient than creating another Client using New(). - -Internals +# Internals Client's methods buffer metrics. The buffer is flushed when either: - - the background goroutine flushes the buffer (every 100ms by default) - - the buffer is full (1440 bytes by default so that IP packets are not - fragmented) + - the background goroutine flushes the buffer (every 100ms by default) + - the buffer is full (1440 bytes by default so that IP packets are not + fragmented) The background goroutine can be disabled using the FlushPeriod(0) option. diff --git a/examples_test.go b/examples_test.go index 45ff0fd..8186112 100644 --- a/examples_test.go +++ b/examples_test.go @@ -5,7 +5,7 @@ import ( "runtime" "time" - "github.com/multiplay/statsd" + "github.com/rocketsciencegg/statsd/v2" ) var ( diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..27c2048 --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module github.com/rocketsciencegg/statsd/v2 + +go 1.16 diff --git a/statsd_test.go b/statsd_test.go index fc7ffe8..42c2681 100644 --- a/statsd_test.go +++ b/statsd_test.go @@ -4,7 +4,6 @@ import ( "bytes" "errors" "io" - "io/ioutil" "net" "sync" "testing" @@ -203,7 +202,7 @@ func TestOddTagsArgs(t *testing.T) { } }() - _, _ = New(TagsFormat(InfluxDB), Tags("tag1")) + _, _ = New(TagsFormat(InfluxDB), Tags("tag1")) //nolint:staticcheck // Intentionally pass an odd tag count to test the panic. t.Fatal("A panic should occur") } @@ -519,7 +518,7 @@ func newServer(t testing.TB, network, addr string, f func([]byte)) *server { s.closed <- true return } - p, err := ioutil.ReadAll(conn) + p, err := io.ReadAll(conn) if err != nil { t.Fatal(err) }