Skip to content

Commit

Permalink
chore: Add support for go1.23 and golangci-lint v1.60.1 (#3101)
Browse files Browse the repository at this point in the history
* Bump min go to 1.22, bump golangci-lint to v1.60.1, regenerate all msgp

* Fix golanci-lint issues

* Fix golanci-lint issues
  • Loading branch information
gaby authored Aug 14, 2024
1 parent e437633 commit 25e3992
Show file tree
Hide file tree
Showing 38 changed files with 1,381 additions and 196 deletions.
6 changes: 3 additions & 3 deletions .github/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Fiber v3 is currently in beta and under active development. While it offers exci

## ⚙️ Installation

Fiber requires **Go version `1.21` or higher** to run. If you need to install or upgrade Go, visit the [official Go download page](https://go.dev/dl/). To start setting up your project. Create a new directory for your project and navigate into it. Then, initialize your project with Go modules by executing the following command in your terminal:
Fiber requires **Go version `1.22` or higher** to run. If you need to install or upgrade Go, visit the [official Go download page](https://go.dev/dl/). To start setting up your project. Create a new directory for your project and navigate into it. Then, initialize your project with Go modules by executing the following command in your terminal:

```bash
go mod init github.com/your/repo
Expand Down Expand Up @@ -124,7 +124,7 @@ We **listen** to our users in [issues](https://github.com/gofiber/fiber/issues),

## ⚠️ Limitations

- Due to Fiber's usage of unsafe, the library may not always be compatible with the latest Go version. Fiber v3 has been tested with Go versions 1.21 and 1.22.
- Due to Fiber's usage of unsafe, the library may not always be compatible with the latest Go version. Fiber v3 has been tested with Go versions 1.22 and 1.23.
- Fiber is not compatible with net/http interfaces. This means you will not be able to use projects like gqlgen, go-swagger, or any others which are part of the net/http ecosystem.

## 👀 Examples
Expand Down Expand Up @@ -615,7 +615,7 @@ List of externally hosted middleware modules and maintained by the [Fiber team](
| :------------------------------------------------ | :-------------------------------------------------------------------------------------------------------------------- |
| [contrib](https://github.com/gofiber/contrib) | Third party middlewares |
| [storage](https://github.com/gofiber/storage) | Premade storage drivers that implement the Storage interface, designed to be used with various Fiber middlewares. |
| [template](https://github.com/gofiber/template) | This package contains 9 template engines that can be used with Fiber `v3` Go version 1.21 or higher is required. |
| [template](https://github.com/gofiber/template) | This package contains 9 template engines that can be used with Fiber `v3` Go version 1.22 or higher is required. |

## 🕶️ Awesome List

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
uses: actions/setup-go@v5
with:
# NOTE: Keep this in sync with the version from go.mod
go-version: "1.21.x"
go-version: "1.22.x"

- name: Run Benchmark
run: set -o pipefail; go test ./... -benchmem -run=^$ -bench . | tee output.txt
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ jobs:
- uses: actions/setup-go@v5
with:
# NOTE: Keep this in sync with the version from go.mod
go-version: "1.21.x"
go-version: "1.22.x"
cache: false

- name: golangci-lint
uses: golangci/golangci-lint-action@v6
with:
# NOTE: Keep this in sync with the version from .golangci.yml
version: v1.59.1
version: v1.60.1
6 changes: 3 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ jobs:
unit:
strategy:
matrix:
go-version: [1.21.x, 1.22.x]
platform: [ubuntu-latest, windows-latest, macos-latest, macos-14]
go-version: [1.22.x, 1.23.x]
platform: [ubuntu-latest, windows-latest, macos-latest, macos-13]
runs-on: ${{ matrix.platform }}
steps:
- name: Fetch Repository
Expand All @@ -31,7 +31,7 @@ jobs:
run: go run gotest.tools/gotestsum@latest -f testname -- ./... -race -count=1 -coverprofile=coverage.txt -covermode=atomic -shuffle=on

- name: Upload coverage reports to Codecov
if: ${{ matrix.platform == 'ubuntu-latest' && matrix.go-version == '1.22.x' }}
if: ${{ matrix.platform == 'ubuntu-latest' && matrix.go-version == '1.23.x' }}
uses: codecov/[email protected]
with:
token: ${{ secrets.CODECOV_TOKEN }}
Expand Down
13 changes: 11 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ markdown:
## lint: 🚨 Run lint checks
.PHONY: lint
lint:
go run github.com/golangci/golangci-lint/cmd/golangci-lint@v1.59.1 run ./...
go run github.com/golangci/golangci-lint/cmd/golangci-lint@v1.60.1 run ./...

## test: 🚦 Execute all tests
.PHONY: test
Expand All @@ -55,4 +55,13 @@ tidy:
## betteralign: 📐 Optimize alignment of fields in structs
.PHONY: betteralign
betteralign:
go run github.com/dkorunic/betteralign/cmd/betteralign@latest -test_files -generated_files -apply ./...
go run github.com/dkorunic/betteralign/cmd/betteralign@latest -test_files -generated_files -apply ./...

## tidy: ⚡️ Generate msgp
.PHONY: msgp
msgp:
go run github.com/tinylib/msgp@latest -file="middleware/cache/manager.go" -o="middleware/cache/manager_msgp.go" -tests=true -unexported
go run github.com/tinylib/msgp@latest -file="middleware/session/data.go" -o="middleware/session/data_msgp.go" -tests=true -unexported
go run github.com/tinylib/msgp@latest -file="middleware/csrf/storage_manager.go" -o="middleware/csrf/storage_manager_msgp.go" -tests=true -unexported
go run github.com/tinylib/msgp@latest -file="middleware/limiter/manager.go" -o="middleware/limiter/manager_msgp.go" -tests=true -unexported
go run github.com/tinylib/msgp@latest -file="middleware/idempotency/response.go" -o="middleware/idempotency/response_msgp.go" -tests=true -unexported
2 changes: 1 addition & 1 deletion client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,7 @@ func setConfigToRequest(req *Request, config ...Config) {
return
}

if cfg.File != nil && len(cfg.File) != 0 {
if len(cfg.File) != 0 {
req.AddFiles(cfg.File...)
return
}
Expand Down
2 changes: 1 addition & 1 deletion client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1422,7 +1422,7 @@ func Test_Set_Config_To_Request(t *testing.T) {
key := struct{}{}

ctx := context.Background()
ctx = context.WithValue(ctx, key, "v1")
ctx = context.WithValue(ctx, key, "v1") //nolint: staticcheck // not needed for tests

req := AcquireRequest()

Expand Down
6 changes: 3 additions & 3 deletions client/request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func Test_Request_Context(t *testing.T) {

require.Nil(t, ctx.Value(key))

ctx = context.WithValue(ctx, key, "string")
ctx = context.WithValue(ctx, key, "string") //nolint: staticcheck // not needed for tests
req.SetContext(ctx)
ctx = req.Context()

Expand Down Expand Up @@ -1603,8 +1603,8 @@ func Benchmark_SetValWithStruct(b *testing.B) {
require.Empty(b, string(p.Peek("TInt")))
require.Empty(b, string(p.Peek("TString")))
require.Empty(b, string(p.Peek("TFloat")))
require.Empty(b, len(p.PeekMulti("TSlice")))
require.Empty(b, len(p.PeekMulti("int_slice")))
require.Empty(b, p.PeekMulti("TSlice"))
require.Empty(b, p.PeekMulti("int_slice"))
})

b.Run("error type should ignore", func(b *testing.B) {
Expand Down
6 changes: 3 additions & 3 deletions ctx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -867,7 +867,7 @@ func Test_Ctx_UserContext(t *testing.T) {
t.Parallel()
testKey := struct{}{}
testValue := "Test Value"
ctx := context.WithValue(context.Background(), testKey, testValue)
ctx := context.WithValue(context.Background(), testKey, testValue) //nolint: staticcheck // not needed for tests
require.Equal(t, testValue, ctx.Value(testKey))
})
}
Expand All @@ -880,7 +880,7 @@ func Test_Ctx_SetUserContext(t *testing.T) {

testKey := struct{}{}
testValue := "Test Value"
ctx := context.WithValue(context.Background(), testKey, testValue)
ctx := context.WithValue(context.Background(), testKey, testValue) //nolint: staticcheck // not needed for tests
c.SetUserContext(ctx)
require.Equal(t, testValue, c.UserContext().Value(testKey))
}
Expand All @@ -900,7 +900,7 @@ func Test_Ctx_UserContext_Multiple_Requests(t *testing.T) {
}

input := utils.CopyString(Query(c, "input", "NO_VALUE"))
ctx = context.WithValue(ctx, testKey, fmt.Sprintf("%s_%s", testValue, input))
ctx = context.WithValue(ctx, testKey, fmt.Sprintf("%s_%s", testValue, input)) //nolint: staticcheck // not needed for tests
c.SetUserContext(ctx)

return c.Status(StatusOK).SendString(fmt.Sprintf("resp_%s_returned", input))
Expand Down
2 changes: 1 addition & 1 deletion docs/intro.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ These docs are for **Fiber v3**, which was released on **March XX, 2024**.

### Installation

First of all, [download](https://go.dev/dl/) and install Go. `1.21` or higher is required.
First of all, [download](https://go.dev/dl/) and install Go. `1.22` or higher is required.

Installation is done using the [`go get`](https://pkg.go.dev/cmd/go/#hdr-Add_dependencies_to_current_module_and_install_them) command:

Expand Down
2 changes: 1 addition & 1 deletion docs/whats_new.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Here's a quick overview of the changes in Fiber `v3`:

## Drop for old Go versions

Fiber `v3` drops support for Go versions below `1.21`. We recommend upgrading to Go `1.21` or higher to use Fiber `v3`.
Fiber `v3` drops support for Go versions below `1.22`. We recommend upgrading to Go `1.22` or higher to use Fiber `v3`.

## 🚀 App

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/gofiber/fiber/v3

go 1.21
go 1.22

require (
github.com/gofiber/utils/v2 v2.0.0-beta.6
Expand Down
4 changes: 1 addition & 3 deletions helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
package fiber

import (
"fmt"
"strings"
"testing"
"time"
Expand Down Expand Up @@ -533,8 +532,7 @@ func Test_Utils_IsNoCache(t *testing.T) {

for _, c := range testCases {
ok := isNoCache(c.string)
require.Equal(t, c.bool, ok,
fmt.Sprintf("want %t, got isNoCache(%s)=%t", c.bool, c.string, ok))
require.Equal(t, c.bool, ok, "want %t, got isNoCache(%s)=%t", c.bool, c.string, ok)
}
}

Expand Down
2 changes: 1 addition & 1 deletion listen.go
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ func (app *App) startupMessage(addr string, isTLS bool, pids string, cfg ListenC
}

fmt.Fprintf(out, "%s\n", fmt.Sprintf(figletFiberText, colors.Red+"v"+Version+colors.Reset)) //nolint:errcheck,revive // ignore error
fmt.Fprintf(out, strings.Repeat("-", 50)+"\n") //nolint:errcheck,revive // ignore error
fmt.Fprintf(out, strings.Repeat("-", 50)+"\n") //nolint:errcheck,revive,govet // ignore error

if host == "0.0.0.0" {
//nolint:errcheck,revive // ignore error
Expand Down
4 changes: 2 additions & 2 deletions middleware/cache/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -880,7 +880,7 @@ func Test_Cache_MaxBytesOrder(t *testing.T) {
for idx, tcase := range cases {
rsp, err := app.Test(httptest.NewRequest(fiber.MethodGet, tcase[0], nil))
require.NoError(t, err)
require.Equal(t, tcase[1], rsp.Header.Get("X-Cache"), fmt.Sprintf("Case %v", idx))
require.Equal(t, tcase[1], rsp.Header.Get("X-Cache"), "Case %v", idx)
}
}

Expand Down Expand Up @@ -914,7 +914,7 @@ func Test_Cache_MaxBytesSizes(t *testing.T) {
for idx, tcase := range cases {
rsp, err := app.Test(httptest.NewRequest(fiber.MethodGet, tcase[0], nil))
require.NoError(t, err)
require.Equal(t, tcase[1], rsp.Header.Get("X-Cache"), fmt.Sprintf("Case %v", idx))
require.Equal(t, tcase[1], rsp.Header.Get("X-Cache"), "Case %v", idx)
}
}

Expand Down
5 changes: 3 additions & 2 deletions middleware/cache/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ import (
"github.com/gofiber/fiber/v3/internal/memory"
)

// go:generate msgp
// msgp -file="manager.go" -o="manager_msgp.go" -tests=false -unexported
// msgp -file="manager.go" -o="manager_msgp.go" -tests=true -unexported
//
//go:generate msgp
type item struct {
headers map[string][]byte
body []byte
Expand Down
Loading

1 comment on commit 25e3992

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 1.50.

Benchmark suite Current: 25e3992 Previous: 87bb93e Ratio
Benchmark_Ctx_IP_With_ProxyHeader_and_IP_Validation 101.2 ns/op 0 B/op 0 allocs/op 60.52 ns/op 0 B/op 0 allocs/op 1.67
Benchmark_Ctx_IP_With_ProxyHeader_and_IP_Validation - ns/op 101.2 ns/op 60.52 ns/op 1.67
Benchmark_Ctx_Send 7.2 ns/op 0 B/op 0 allocs/op 4.661 ns/op 0 B/op 0 allocs/op 1.54
Benchmark_Ctx_Send - ns/op 7.2 ns/op 4.661 ns/op 1.54
Benchmark_Utils_GetOffer/1_parameter 211.2 ns/op 0 B/op 0 allocs/op 136.1 ns/op 0 B/op 0 allocs/op 1.55
Benchmark_Utils_GetOffer/1_parameter - ns/op 211.2 ns/op 136.1 ns/op 1.55
Benchmark_Middleware_BasicAuth - B/op 80 B/op 48 B/op 1.67
Benchmark_Middleware_BasicAuth - allocs/op 5 allocs/op 3 allocs/op 1.67
Benchmark_Middleware_BasicAuth_Upper - B/op 80 B/op 48 B/op 1.67
Benchmark_Middleware_BasicAuth_Upper - allocs/op 5 allocs/op 3 allocs/op 1.67
Benchmark_CORS_NewHandler - B/op 16 B/op 0 B/op +∞
Benchmark_CORS_NewHandler - allocs/op 1 allocs/op 0 allocs/op +∞
Benchmark_CORS_NewHandlerSingleOrigin - B/op 16 B/op 0 B/op +∞
Benchmark_CORS_NewHandlerSingleOrigin - allocs/op 1 allocs/op 0 allocs/op +∞
Benchmark_CORS_NewHandlerPreflight 1153 ns/op 104 B/op 5 allocs/op 759.2 ns/op 0 B/op 0 allocs/op 1.52
Benchmark_CORS_NewHandlerPreflight - ns/op 1153 ns/op 759.2 ns/op 1.52
Benchmark_CORS_NewHandlerPreflight - B/op 104 B/op 0 B/op +∞
Benchmark_CORS_NewHandlerPreflight - allocs/op 5 allocs/op 0 allocs/op +∞
Benchmark_CORS_NewHandlerPreflightSingleOrigin 1157 ns/op 104 B/op 5 allocs/op 757.5 ns/op 0 B/op 0 allocs/op 1.53
Benchmark_CORS_NewHandlerPreflightSingleOrigin - ns/op 1157 ns/op 757.5 ns/op 1.53
Benchmark_CORS_NewHandlerPreflightSingleOrigin - B/op 104 B/op 0 B/op +∞
Benchmark_CORS_NewHandlerPreflightSingleOrigin - allocs/op 5 allocs/op 0 allocs/op +∞
Benchmark_CORS_NewHandlerPreflightWildcard 1062 ns/op 104 B/op 5 allocs/op 691 ns/op 0 B/op 0 allocs/op 1.54
Benchmark_CORS_NewHandlerPreflightWildcard - ns/op 1062 ns/op 691 ns/op 1.54
Benchmark_CORS_NewHandlerPreflightWildcard - B/op 104 B/op 0 B/op +∞
Benchmark_CORS_NewHandlerPreflightWildcard - allocs/op 5 allocs/op 0 allocs/op +∞
Benchmark_Middleware_CSRF_GenerateToken - B/op 516 B/op 326 B/op 1.58
Benchmark_Middleware_CSRF_GenerateToken - allocs/op 10 allocs/op 6 allocs/op 1.67

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.