From 465166ba16781b167c5767afa526e833590d799b Mon Sep 17 00:00:00 2001 From: Joe Chen Date: Sun, 8 Nov 2026 00:56:38 +0000 Subject: [PATCH 1/3] ci: use Go 1.27 and pin GitHub Actions to commit SHAs Amp-Thread-ID: https://ampcode.com/threads/T-01a1b893-07c3-7507-afd4-7e8161140208 Co-authored-by: Amp --- .github/workflows/go.yml | 18 +++++++++++------- .golangci.yml | 38 +++++++++++++++++++++++++------------- binding.go | 6 +++--- binding_test.go | 8 ++++---- 4 files changed, 43 insertions(+), 27 deletions(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index d612782..fe4f75e 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -22,9 +22,13 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout code - uses: actions/checkout@v3 + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + - name: Install Go + uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0 + with: + go-version: 1.27.x - name: Run golangci-lint - uses: golangci/golangci-lint-action@v3 + uses: golangci/golangci-lint-action@ba0d7d2ec06a0ea1cb5fa41b2e4a3ab91d21278a # v9.3.0 with: version: latest args: --timeout=30m @@ -33,20 +37,20 @@ jobs: name: Test strategy: matrix: - go-version: [ 1.20.x, 1.21.x ] + go-version: [ 1.27.x ] platform: [ ubuntu-latest, macos-latest, windows-latest ] runs-on: ${{ matrix.platform }} steps: - name: Checkout code - uses: actions/checkout@v3 + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - name: Install Go - uses: actions/setup-go@v4 + uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0 with: go-version: ${{ matrix.go-version }} - name: Run tests with coverage run: go test -shuffle=on -v -race -coverprofile=coverage -covermode=atomic - name: Upload coverage report to Codecov - uses: codecov/codecov-action@v1.5.0 + uses: codecov/codecov-action@303a32d7a59b442fa8d48b6a1cc6825c09c847a5 # v7.1.1 with: - file: ./coverage + files: ./coverage flags: unittests diff --git a/.golangci.yml b/.golangci.yml index 82dd9ef..6937629 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,19 +1,31 @@ -linters-settings: - nakedret: - max-func-lines: 0 # Disallow any unnamed return statement - +version: "2" linters: enable: - - unused - - errcheck - - gosimple - - govet - - ineffassign - - staticcheck - - typecheck - nakedret - - gofmt - rowserrcheck - unconvert - - goimports - unparam + settings: + nakedret: + max-func-lines: 0 # Disallow any unnamed return statement + exclusions: + generated: lax + presets: + - comments + - common-false-positives + - legacy + - std-error-handling + paths: + - third_party$ + - builtin$ + - examples$ +formatters: + enable: + - gofmt + - goimports + exclusions: + generated: lax + paths: + - third_party$ + - builtin$ + - examples$ diff --git a/binding.go b/binding.go index 94e2add..797b7a5 100644 --- a/binding.go +++ b/binding.go @@ -42,7 +42,7 @@ func (invoke errorHandlerInvoker) Invoke(args []interface{}) ([]reflect.Value, e // ensureNotPointer panics if the given value is a pointer. func ensureNotPointer(model interface{}) { - if reflect.TypeOf(model).Kind() == reflect.Ptr { + if reflect.TypeOf(model).Kind() == reflect.Pointer { panic("binding: pointer can not be accepted as binding model") } } @@ -207,7 +207,7 @@ func mapForm( files map[string][]*multipart.FileHeader, errs Errors, ) Errors { - if obj.Kind() == reflect.Ptr { + if obj.Kind() == reflect.Pointer { obj = obj.Elem() } typ := obj.Type() @@ -219,7 +219,7 @@ func mapForm( continue } - if typeField.Type.Kind() == reflect.Ptr && typeField.Anonymous { + if typeField.Type.Kind() == reflect.Pointer && typeField.Anonymous { structField.Set(reflect.New(typeField.Type.Elem())) errs = mapForm(structField.Elem(), form, files, errs) if reflect.DeepEqual(structField.Elem().Interface(), reflect.Zero(structField.Elem().Type()).Interface()) { diff --git a/binding_test.go b/binding_test.go index 3b92134..7c0da42 100644 --- a/binding_test.go +++ b/binding_test.go @@ -73,7 +73,7 @@ func TestJSON(t *testing.T) { fastInvokerHandler := func(c flamego.Context, errs Errors) { c.ResponseWriter().WriteHeader(http.StatusBadRequest) - _, _ = c.ResponseWriter().Write([]byte(fmt.Sprintf("Oops! Error occurred: %v", errs[0].Err))) + _, _ = fmt.Fprintf(c.ResponseWriter(), "Oops! Error occurred: %v", errs[0].Err) } tests := []struct { @@ -398,7 +398,7 @@ func TestYAML(t *testing.T) { } fastInvokerHandler := func(c flamego.Context, errs Errors) { c.ResponseWriter().WriteHeader(http.StatusBadRequest) - _, _ = c.ResponseWriter().Write([]byte(fmt.Sprintf("Oops! Error occurred: %v", errs[0].Err))) + _, _ = fmt.Fprintf(c.ResponseWriter(), "Oops! Error occurred: %v", errs[0].Err) } tests := []struct { name string @@ -853,7 +853,7 @@ func TestForm(t *testing.T) { fastInvokerHandler := func(c flamego.Context, errs Errors) { c.ResponseWriter().WriteHeader(http.StatusBadRequest) - _, _ = c.ResponseWriter().Write([]byte(fmt.Sprintf("Oops! Error occurred: %v", errs[0].Err))) + _, _ = fmt.Fprintf(c.ResponseWriter(), "Oops! Error occurred: %v", errs[0].Err) } tests := []struct { @@ -1206,7 +1206,7 @@ func TestMultipartForm(t *testing.T) { fastInvokerHandler := func(c flamego.Context, errs Errors) { c.ResponseWriter().WriteHeader(http.StatusBadRequest) - _, _ = c.ResponseWriter().Write([]byte(fmt.Sprintf("Oops! Error occurred: %v", errs[0].Err))) + _, _ = fmt.Fprintf(c.ResponseWriter(), "Oops! Error occurred: %v", errs[0].Err) } tests := []struct { From e5fbc793503cceedb9d8f36fc7a403d87031009a Mon Sep 17 00:00:00 2001 From: Joe Chen Date: Sun, 8 Nov 2026 01:35:58 +0000 Subject: [PATCH 2/3] ci: align golangci-lint config with flamego/flamego Amp-Thread-ID: https://ampcode.com/threads/T-01a1b893-07c3-7507-afd4-7e8161140208 Co-authored-by: Amp --- .golangci.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.golangci.yml b/.golangci.yml index 6937629..c8c1f59 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -6,6 +6,12 @@ linters: - unconvert - unparam settings: + staticcheck: + checks: + - all + - "-SA1019" # This project is under active refactoring and not all code is up to date. + - "-QF1001" # I'm a math noob + - "-ST1016" # Some legit code uses this pattern nakedret: max-func-lines: 0 # Disallow any unnamed return statement exclusions: From 75a769f0014b0956c67dc887c0d07434f041cbfe Mon Sep 17 00:00:00 2001 From: Joe Chen Date: Sun, 8 Nov 2026 14:20:02 +0000 Subject: [PATCH 3/3] ci: drop SA1019 and ST1016 exclusions from golangci-lint config Amp-Thread-ID: https://ampcode.com/threads/T-01a1b893-07c3-7507-afd4-7e8161140208 Co-authored-by: Amp --- .golangci.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index c8c1f59..e49a45f 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -9,9 +9,7 @@ linters: staticcheck: checks: - all - - "-SA1019" # This project is under active refactoring and not all code is up to date. - "-QF1001" # I'm a math noob - - "-ST1016" # Some legit code uses this pattern nakedret: max-func-lines: 0 # Disallow any unnamed return statement exclusions: