From a975d6bbfb0492614e8343a313c960f841379365 Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Fri, 19 Apr 2024 08:30:07 -1000 Subject: [PATCH] Updates to latest actions and fixes golangci-lint drift Signed-off-by: Adrian Cole --- .github/workflows/ci.yml | 10 ++++------ .golangci.yml | 11 +++++++---- middleware/http/server_test.go | 8 ++++---- middleware/http/transport_test.go | 14 +++++++------- reporter/http/http_test.go | 6 +++--- span_options.go | 10 +++++----- 6 files changed, 30 insertions(+), 29 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1654134..2b88177 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -10,8 +10,6 @@ on: jobs: "CI": - env: - GO111MODULE: on runs-on: ${{ matrix.os }} strategy: matrix: @@ -25,17 +23,17 @@ jobs: steps: # Set fetch-depth: 0 to fetch commit history and tags for use in version calculation - name: Check out code - uses: actions/checkout@v2.3.4 + uses: actions/checkout@v4 with: fetch-depth: 0 - name: Setup go - uses: actions/setup-go@v1 + uses: actions/setup-go@v5 with: go-version: ${{ matrix.go }} - name: Lint files - uses: golangci/golangci-lint-action@v2 + uses: golangci/golangci-lint-action@v4 with: # Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version. version: latest @@ -46,7 +44,7 @@ jobs: CGO_ENABLED: 1 - name: Upload coverage to Codecov - uses: codecov/codecov-action@v3 + uses: codecov/codecov-action@v4 env: CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} with: diff --git a/.golangci.yml b/.golangci.yml index e990f02..0c797fb 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,6 +1,8 @@ run: - deadline: 5m - skip-dirs: + timeout: 5m + +issues: + exclude-dirs: - zipkin_proto3 linters: @@ -16,6 +18,7 @@ linters: - lll - misspell - nakedret + - revive - unparam - unused @@ -26,5 +29,5 @@ linters-settings: line-length: 170 gocyclo: min-complexity: 20 - golint: - min-confidence: 0.85 + revive: + confidence: 0.85 diff --git a/middleware/http/server_test.go b/middleware/http/server_test.go index 13c93d1..5ceb860 100644 --- a/middleware/http/server_test.go +++ b/middleware/http/server_test.go @@ -31,7 +31,7 @@ var ( ) func httpHandler(code int, headers http.Header, body *bytes.Buffer) http.HandlerFunc { - return func(w http.ResponseWriter, r *http.Request) { + return func(w http.ResponseWriter, _ *http.Request) { w.WriteHeader(code) for key, value := range headers { w.Header().Add(key, value[0]) @@ -221,9 +221,9 @@ func TestHTTPRequestSampler(t *testing.T) { samplers := []func(r *http.Request) *bool{ nil, - func(r *http.Request) *bool { return mw.Sample() }, - func(r *http.Request) *bool { return mw.Discard() }, - func(r *http.Request) *bool { return nil }, + func(*http.Request) *bool { return mw.Sample() }, + func(*http.Request) *bool { return mw.Discard() }, + func(*http.Request) *bool { return nil }, } for idx, sampler := range samplers { diff --git a/middleware/http/transport_test.go b/middleware/http/transport_test.go index d86f023..2e2347d 100644 --- a/middleware/http/transport_test.go +++ b/middleware/http/transport_test.go @@ -44,7 +44,7 @@ func TestRoundTripErrHandlingForRoundTripError(t *testing.T) { req, _ := http.NewRequest("GET", "localhost", nil) tr, _ := NewTransport( tracer, - TransportErrHandler(func(_ zipkin.Span, err error, statusCode int) { + TransportErrHandler(func(_ zipkin.Span, err error, _ int) { if want, have := expectedErr, err; want != have { t.Errorf("unexpected error, want %q, have %q", want, have) } @@ -81,7 +81,7 @@ func TestRoundTripErrHandlingForStatusCode(t *testing.T) { } for _, tc := range tcs { - srv := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) { + srv := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, _ *http.Request) { rw.WriteHeader(tc.actualStatusCode) })) @@ -92,7 +92,7 @@ func TestRoundTripErrHandlingForStatusCode(t *testing.T) { req, _ := http.NewRequest("GET", srv.URL, nil) tr, _ := NewTransport( tracer, - TransportErrHandler(func(_ zipkin.Span, err error, statusCode int) { + TransportErrHandler(func(_ zipkin.Span, _ error, statusCode int) { if want, have := tc.expectedError, statusCode; want != 0 && want != have { t.Errorf("unexpected status code, want %d, have %d", want, have) } @@ -163,19 +163,19 @@ func TestTransportRequestSamplerOverridesSamplingFromContext(t *testing.T) { // Test RequestSampler override sample -> no sample { Sampler: zipkin.AlwaysSample, - RequestSampler: func(_ *http.Request) *bool { return Discard() }, + RequestSampler: func(*http.Request) *bool { return Discard() }, ExpectedSampling: "0", }, // Test RequestSampler override no sample -> sample { Sampler: zipkin.NeverSample, - RequestSampler: func(_ *http.Request) *bool { return Sample() }, + RequestSampler: func(*http.Request) *bool { return Sample() }, ExpectedSampling: "1", }, // Test RequestSampler pass through of sampled decision { Sampler: zipkin.AlwaysSample, - RequestSampler: func(r *http.Request) *bool { + RequestSampler: func(*http.Request) *bool { return nil }, ExpectedSampling: "1", @@ -183,7 +183,7 @@ func TestTransportRequestSamplerOverridesSamplingFromContext(t *testing.T) { // Test RequestSampler pass through of not sampled decision { Sampler: zipkin.NeverSample, - RequestSampler: func(r *http.Request) *bool { + RequestSampler: func(*http.Request) *bool { return nil }, ExpectedSampling: "0", diff --git a/reporter/http/http_test.go b/reporter/http/http_test.go index 3fd9f5a..2394528 100644 --- a/reporter/http/http_test.go +++ b/reporter/http/http_test.go @@ -53,7 +53,7 @@ func generateSpans(n int) []*model.SpanModel { func newTestServer(t *testing.T, spans []*model.SpanModel, serializer reporter.SpanSerializer, onReceive func(int)) *httptest.Server { sofar := 0 - return httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + return httptest.NewServer(http.HandlerFunc(func(_ http.ResponseWriter, r *http.Request) { if r.Method != "POST" { t.Errorf("expected 'POST' request, got '%s'", r.Method) } @@ -179,7 +179,7 @@ func TestSpanCustomHeaders(t *testing.T) { }, } var haveHeaders http.Header - ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + ts := httptest.NewServer(http.HandlerFunc(func(_ http.ResponseWriter, r *http.Request) { haveHeaders = r.Header })) defer ts.Close() @@ -207,7 +207,7 @@ func TestB3SamplingHeader(t *testing.T) { serializer := reporter.JSONSerializer{} var haveHeaders map[string][]string - ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + ts := httptest.NewServer(http.HandlerFunc(func(_ http.ResponseWriter, r *http.Request) { haveHeaders = r.Header })) defer ts.Close() diff --git a/span_options.go b/span_options.go index 0eabeaa..ad9f5c2 100644 --- a/span_options.go +++ b/span_options.go @@ -26,7 +26,7 @@ type SpanOption func(t *Tracer, s *spanImpl) // Kind sets the kind of the span being created. func Kind(kind model.Kind) SpanOption { - return func(t *Tracer, s *spanImpl) { + return func(_ *Tracer, s *spanImpl) { s.Kind = kind } } @@ -54,14 +54,14 @@ func Parent(sc model.SpanContext) SpanOption { // StartTime uses a given start time for the span being created. func StartTime(start time.Time) SpanOption { - return func(t *Tracer, s *spanImpl) { + return func(_ *Tracer, s *spanImpl) { s.Timestamp = start } } // RemoteEndpoint sets the remote endpoint of the span being created. func RemoteEndpoint(e *model.Endpoint) SpanOption { - return func(t *Tracer, s *spanImpl) { + return func(_ *Tracer, s *spanImpl) { s.RemoteEndpoint = e } } @@ -69,7 +69,7 @@ func RemoteEndpoint(e *model.Endpoint) SpanOption { // Tags sets initial tags for the span being created. If default tracer tags // are present they will be overwritten on key collisions. func Tags(tags map[string]string) SpanOption { - return func(t *Tracer, s *spanImpl) { + return func(_ *Tracer, s *spanImpl) { for k, v := range tags { s.Tags[k] = v } @@ -82,7 +82,7 @@ func Tags(tags map[string]string) SpanOption { // This is available if late tag data is expected to be only available after the // required finish time of the Span. func FlushOnFinish(b bool) SpanOption { - return func(t *Tracer, s *spanImpl) { + return func(_ *Tracer, s *spanImpl) { s.flushOnFinish = b } }