mirror of
https://github.com/gofiber/fiber.git
synced 2025-02-07 00:12:00 +00:00
Bump golangci-lint to v1.59.1 (#3029)
This commit is contained in:
parent
e561026384
commit
46fffe4397
2
.github/workflows/linter.yml
vendored
2
.github/workflows/linter.yml
vendored
@ -33,4 +33,4 @@ jobs:
|
||||
uses: golangci/golangci-lint-action@v6
|
||||
with:
|
||||
# NOTE: Keep this in sync with the version from .golangci.yml
|
||||
version: v1.57.1
|
||||
version: v1.59.1
|
||||
|
@ -236,11 +236,9 @@ linters-settings:
|
||||
time-layout: false # TODO: Set to true
|
||||
crypto-hash: true
|
||||
default-rpc-path: true
|
||||
os-dev-null: true
|
||||
sql-isolation-level: true
|
||||
tls-signature-scheme: true
|
||||
constant-kind: true
|
||||
syslog-priority: true
|
||||
|
||||
wrapcheck:
|
||||
ignorePackageGlobs:
|
||||
@ -256,7 +254,7 @@ issues:
|
||||
- internal # TODO: Do not ignore interal packages
|
||||
exclude-rules:
|
||||
- linters:
|
||||
- goerr113
|
||||
- err113
|
||||
text: 'do not define dynamic errors, use wrapped static errors instead*'
|
||||
- path: log/.*\.go
|
||||
linters:
|
||||
@ -265,6 +263,7 @@ issues:
|
||||
- path: _test\.go
|
||||
linters:
|
||||
- bodyclose
|
||||
- err113
|
||||
# fix: true
|
||||
|
||||
linters:
|
||||
@ -286,7 +285,6 @@ linters:
|
||||
- errchkjson
|
||||
- errname
|
||||
- errorlint
|
||||
- execinquery
|
||||
- exhaustive
|
||||
# - exhaustivestruct
|
||||
# - exhaustruct
|
||||
@ -306,7 +304,7 @@ linters:
|
||||
# - gocyclo
|
||||
# - godot
|
||||
# - godox
|
||||
- goerr113
|
||||
- err113
|
||||
- gofmt
|
||||
- gofumpt
|
||||
# - goheader
|
||||
|
2
Makefile
2
Makefile
@ -30,7 +30,7 @@ format:
|
||||
## lint: 🚨 Run lint checks
|
||||
.PHONY: lint
|
||||
lint:
|
||||
go run github.com/golangci/golangci-lint/cmd/golangci-lint@v1.57.1 run ./...
|
||||
go run github.com/golangci/golangci-lint/cmd/golangci-lint@v1.59.1 run ./...
|
||||
|
||||
## test: 🚦 Execute all tests
|
||||
.PHONY: test
|
||||
|
@ -4274,11 +4274,11 @@ func Test_Ctx_BodyStreamWriter(t *testing.T) {
|
||||
ctx := &fasthttp.RequestCtx{}
|
||||
|
||||
ctx.SetBodyStreamWriter(func(w *bufio.Writer) {
|
||||
fmt.Fprintf(w, "body writer line 1\n")
|
||||
fmt.Fprintf(w, "body writer line 1\n") //nolint: errcheck // It is fine to ignore the error
|
||||
if err := w.Flush(); err != nil {
|
||||
t.Errorf("unexpected error: %s", err)
|
||||
}
|
||||
fmt.Fprintf(w, "body writer line 2\n")
|
||||
fmt.Fprintf(w, "body writer line 2\n") //nolint: errcheck // It is fine to ignore the error
|
||||
})
|
||||
|
||||
require.True(t, ctx.IsBodyStream())
|
||||
|
47
listen.go
47
listen.go
@ -351,32 +351,38 @@ func (app *App) startupMessage(addr string, isTLS bool, pids string, cfg ListenC
|
||||
out = colorable.NewNonColorable(os.Stdout)
|
||||
}
|
||||
|
||||
_, _ = fmt.Fprintf(out, "%s\n", fmt.Sprintf(figletFiberText, colors.Red+"v"+Version+colors.Reset))
|
||||
_, _ = fmt.Fprintf(out, strings.Repeat("-", 50)+"\n")
|
||||
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
|
||||
|
||||
if host == "0.0.0.0" {
|
||||
_, _ = fmt.Fprintf(out,
|
||||
//nolint:errcheck,revive // ignore error
|
||||
fmt.Fprintf(out,
|
||||
"%sINFO%s Server started on: \t%s%s://127.0.0.1:%s%s (bound on host 0.0.0.0 and port %s)\n",
|
||||
colors.Green, colors.Reset, colors.Blue, scheme, port, colors.Reset, port)
|
||||
} else {
|
||||
_, _ = fmt.Fprintf(out,
|
||||
//nolint:errcheck,revive // ignore error
|
||||
fmt.Fprintf(out,
|
||||
"%sINFO%s Server started on: \t%s%s%s\n",
|
||||
colors.Green, colors.Reset, colors.Blue, fmt.Sprintf("%s://%s:%s", scheme, host, port), colors.Reset)
|
||||
}
|
||||
|
||||
if app.config.AppName != "" {
|
||||
_, _ = fmt.Fprintf(out, "%sINFO%s Application name: \t\t%s%s%s\n", colors.Green, colors.Reset, colors.Blue, app.config.AppName, colors.Reset)
|
||||
fmt.Fprintf(out, "%sINFO%s Application name: \t\t%s%s%s\n", colors.Green, colors.Reset, colors.Blue, app.config.AppName, colors.Reset) //nolint:errcheck,revive // ignore error
|
||||
}
|
||||
_, _ = fmt.Fprintf(out,
|
||||
|
||||
//nolint:errcheck,revive // ignore error
|
||||
fmt.Fprintf(out,
|
||||
"%sINFO%s Total handlers count: \t%s%s%s\n",
|
||||
colors.Green, colors.Reset, colors.Blue, strconv.Itoa(int(app.handlersCount)), colors.Reset)
|
||||
|
||||
if isPrefork == "Enabled" {
|
||||
_, _ = fmt.Fprintf(out, "%sINFO%s Prefork: \t\t\t%s%s%s\n", colors.Green, colors.Reset, colors.Blue, isPrefork, colors.Reset)
|
||||
fmt.Fprintf(out, "%sINFO%s Prefork: \t\t\t%s%s%s\n", colors.Green, colors.Reset, colors.Blue, isPrefork, colors.Reset) //nolint:errcheck,revive // ignore error
|
||||
} else {
|
||||
_, _ = fmt.Fprintf(out, "%sINFO%s Prefork: \t\t\t%s%s%s\n", colors.Green, colors.Reset, colors.Red, isPrefork, colors.Reset)
|
||||
fmt.Fprintf(out, "%sINFO%s Prefork: \t\t\t%s%s%s\n", colors.Green, colors.Reset, colors.Red, isPrefork, colors.Reset) //nolint:errcheck,revive // ignore error
|
||||
}
|
||||
_, _ = fmt.Fprintf(out, "%sINFO%s PID: \t\t\t%s%v%s\n", colors.Green, colors.Reset, colors.Blue, os.Getpid(), colors.Reset)
|
||||
_, _ = fmt.Fprintf(out, "%sINFO%s Total process count: \t%s%s%s\n", colors.Green, colors.Reset, colors.Blue, procs, colors.Reset)
|
||||
|
||||
fmt.Fprintf(out, "%sINFO%s PID: \t\t\t%s%v%s\n", colors.Green, colors.Reset, colors.Blue, os.Getpid(), colors.Reset) //nolint:errcheck,revive // ignore error
|
||||
fmt.Fprintf(out, "%sINFO%s Total process count: \t%s%s%s\n", colors.Green, colors.Reset, colors.Blue, procs, colors.Reset) //nolint:errcheck,revive // ignore error
|
||||
|
||||
if cfg.EnablePrefork {
|
||||
// Turn the `pids` variable (in the form ",a,b,c,d,e,f,etc") into a slice of PIDs
|
||||
@ -387,27 +393,30 @@ func (app *App) startupMessage(addr string, isTLS bool, pids string, cfg ListenC
|
||||
}
|
||||
}
|
||||
|
||||
_, _ = fmt.Fprintf(out, "%sINFO%s Child PIDs: \t\t%s", colors.Green, colors.Reset, colors.Blue)
|
||||
fmt.Fprintf(out, "%sINFO%s Child PIDs: \t\t%s", colors.Green, colors.Reset, colors.Blue) //nolint:errcheck,revive // ignore error
|
||||
totalPids := len(pidSlice)
|
||||
rowTotalPidCount := 10
|
||||
|
||||
for i := 0; i < totalPids; i += rowTotalPidCount {
|
||||
start := i
|
||||
end := i + rowTotalPidCount
|
||||
|
||||
if end > totalPids {
|
||||
end = totalPids
|
||||
}
|
||||
|
||||
for n, pid := range pidSlice[start:end] {
|
||||
_, _ = fmt.Fprintf(out, "%s", pid)
|
||||
fmt.Fprintf(out, "%s", pid) //nolint:errcheck,revive // ignore error
|
||||
if n+1 != len(pidSlice[start:end]) {
|
||||
_, _ = fmt.Fprintf(out, ", ")
|
||||
fmt.Fprintf(out, ", ") //nolint:errcheck,revive // ignore error
|
||||
}
|
||||
}
|
||||
_, _ = fmt.Fprintf(out, "\n%s", colors.Reset)
|
||||
fmt.Fprintf(out, "\n%s", colors.Reset) //nolint:errcheck,revive // ignore error
|
||||
}
|
||||
}
|
||||
|
||||
// add new Line as spacer
|
||||
_, _ = fmt.Fprintf(out, "\n%s", colors.Reset)
|
||||
fmt.Fprintf(out, "\n%s", colors.Reset) //nolint:errcheck,revive // ignore error
|
||||
}
|
||||
|
||||
// printRoutesMessage print all routes with method, path, name and handlers
|
||||
@ -449,10 +458,12 @@ func (app *App) printRoutesMessage() {
|
||||
return routes[i].path < routes[j].path
|
||||
})
|
||||
|
||||
_, _ = fmt.Fprintf(w, "%smethod\t%s| %spath\t%s| %sname\t%s| %shandlers\t%s\n", colors.Blue, colors.White, colors.Green, colors.White, colors.Cyan, colors.White, colors.Yellow, colors.Reset)
|
||||
_, _ = fmt.Fprintf(w, "%s------\t%s| %s----\t%s| %s----\t%s| %s--------\t%s\n", colors.Blue, colors.White, colors.Green, colors.White, colors.Cyan, colors.White, colors.Yellow, colors.Reset)
|
||||
fmt.Fprintf(w, "%smethod\t%s| %spath\t%s| %sname\t%s| %shandlers\t%s\n", colors.Blue, colors.White, colors.Green, colors.White, colors.Cyan, colors.White, colors.Yellow, colors.Reset) //nolint:errcheck,revive // ignore error
|
||||
fmt.Fprintf(w, "%s------\t%s| %s----\t%s| %s----\t%s| %s--------\t%s\n", colors.Blue, colors.White, colors.Green, colors.White, colors.Cyan, colors.White, colors.Yellow, colors.Reset) //nolint:errcheck,revive // ignore error
|
||||
|
||||
for _, route := range routes {
|
||||
_, _ = fmt.Fprintf(w, "%s%s\t%s| %s%s\t%s| %s%s\t%s| %s%s%s\n", colors.Blue, route.method, colors.White, colors.Green, route.path, colors.White, colors.Cyan, route.name, colors.White, colors.Yellow, route.handlers, colors.Reset)
|
||||
//nolint:errcheck,revive // ignore error
|
||||
fmt.Fprintf(w, "%s%s\t%s| %s%s\t%s| %s%s\t%s| %s%s%s\n", colors.Blue, route.method, colors.White, colors.Green, route.path, colors.White, colors.Cyan, route.name, colors.White, colors.Yellow, route.handlers, colors.Reset)
|
||||
}
|
||||
|
||||
_ = w.Flush() //nolint:errcheck // It is fine to ignore the error here
|
||||
|
@ -53,9 +53,9 @@ func (l *defaultLogger) privateLogf(lv Level, format string, fmtArgs []any) {
|
||||
buf.WriteString(level)
|
||||
|
||||
if len(fmtArgs) > 0 {
|
||||
_, _ = fmt.Fprintf(buf, format, fmtArgs...)
|
||||
_, _ = fmt.Fprintf(buf, format, fmtArgs...) //nolint: errcheck // It is fine to ignore the error
|
||||
} else {
|
||||
_, _ = fmt.Fprint(buf, fmtArgs...)
|
||||
_, _ = fmt.Fprint(buf, fmtArgs...) //nolint: errcheck // It is fine to ignore the error
|
||||
}
|
||||
|
||||
_ = l.stdlog.Output(l.depth, buf.String()) //nolint:errcheck // It is fine to ignore the error
|
||||
|
@ -13,6 +13,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/gofiber/fiber/v3"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/valyala/fasthttp"
|
||||
)
|
||||
@ -42,31 +43,31 @@ func Test_HTTPHandler(t *testing.T) {
|
||||
callsCount := 0
|
||||
nethttpH := func(w http.ResponseWriter, r *http.Request) {
|
||||
callsCount++
|
||||
require.Equal(t, expectedMethod, r.Method, "Method")
|
||||
require.Equal(t, expectedProto, r.Proto, "Proto")
|
||||
require.Equal(t, expectedProtoMajor, r.ProtoMajor, "ProtoMajor")
|
||||
require.Equal(t, expectedProtoMinor, r.ProtoMinor, "ProtoMinor")
|
||||
require.Equal(t, expectedRequestURI, r.RequestURI, "RequestURI")
|
||||
require.Equal(t, expectedContentLength, int(r.ContentLength), "ContentLength")
|
||||
require.Empty(t, r.TransferEncoding, "TransferEncoding")
|
||||
require.Equal(t, expectedHost, r.Host, "Host")
|
||||
require.Equal(t, expectedRemoteAddr, r.RemoteAddr, "RemoteAddr")
|
||||
assert.Equal(t, expectedMethod, r.Method, "Method")
|
||||
assert.Equal(t, expectedProto, r.Proto, "Proto")
|
||||
assert.Equal(t, expectedProtoMajor, r.ProtoMajor, "ProtoMajor")
|
||||
assert.Equal(t, expectedProtoMinor, r.ProtoMinor, "ProtoMinor")
|
||||
assert.Equal(t, expectedRequestURI, r.RequestURI, "RequestURI")
|
||||
assert.Equal(t, expectedContentLength, int(r.ContentLength), "ContentLength")
|
||||
assert.Empty(t, r.TransferEncoding, "TransferEncoding")
|
||||
assert.Equal(t, expectedHost, r.Host, "Host")
|
||||
assert.Equal(t, expectedRemoteAddr, r.RemoteAddr, "RemoteAddr")
|
||||
|
||||
body, err := io.ReadAll(r.Body)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, expectedBody, string(body), "Body")
|
||||
require.Equal(t, expectedURL, r.URL, "URL")
|
||||
require.Equal(t, expectedContextValue, r.Context().Value(expectedContextKey), "Context")
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, expectedBody, string(body), "Body")
|
||||
assert.Equal(t, expectedURL, r.URL, "URL")
|
||||
assert.Equal(t, expectedContextValue, r.Context().Value(expectedContextKey), "Context")
|
||||
|
||||
for k, expectedV := range expectedHeader {
|
||||
v := r.Header.Get(k)
|
||||
require.Equal(t, expectedV, v, "Header")
|
||||
assert.Equal(t, expectedV, v, "Header")
|
||||
}
|
||||
|
||||
w.Header().Set("Header1", "value1")
|
||||
w.Header().Set("Header2", "value2")
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
fmt.Fprintf(w, "request body is %q", body)
|
||||
fmt.Fprintf(w, "request body is %q", body) //nolint:errcheck // not needed
|
||||
}
|
||||
fiberH := HTTPHandlerFunc(http.HandlerFunc(nethttpH))
|
||||
fiberH = setFiberContextValueMiddleware(fiberH, expectedContextKey, expectedContextValue)
|
||||
|
@ -161,7 +161,7 @@ func writeLog(w io.Writer, msg []byte) {
|
||||
// Write error to output
|
||||
if _, err := w.Write([]byte(err.Error())); err != nil {
|
||||
// There is something wrong with the given io.Writer
|
||||
_, _ = fmt.Fprintf(os.Stderr, "Failed to write to log, %v\n", err)
|
||||
_, _ = fmt.Fprintf(os.Stderr, "Failed to write to log, %v\n", err) //nolint: errcheck // It is fine to ignore the error
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -128,7 +128,7 @@ func Test_Logger_Done(t *testing.T) {
|
||||
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, fiber.StatusOK, resp.StatusCode)
|
||||
require.Greater(t, buf.Len(), 0)
|
||||
require.Positive(t, buf.Len(), 0)
|
||||
}
|
||||
|
||||
// go test -run Test_Logger_ErrorTimeZone
|
||||
@ -625,7 +625,7 @@ func Test_Logger_ByteSent_Streaming(t *testing.T) {
|
||||
for {
|
||||
i++
|
||||
msg := fmt.Sprintf("%d - the time is %v", i, time.Now())
|
||||
fmt.Fprintf(w, "data: Message: %s\n\n", msg)
|
||||
fmt.Fprintf(w, "data: Message: %s\n\n", msg) //nolint:errcheck // ignore error
|
||||
err := w.Flush()
|
||||
if err != nil {
|
||||
break
|
||||
|
Loading…
x
Reference in New Issue
Block a user