diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 35e78e6..32eb779 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -7,4 +7,4 @@ jobs: - uses: actions/checkout@v3 - uses: golangci/golangci-lint-action@v3 with: - version: v1.55.2 + version: v1.56.2 diff --git a/atreugo_test.go b/atreugo_test.go index 0c4dec6..c2997ea 100644 --- a/atreugo_test.go +++ b/atreugo_test.go @@ -48,19 +48,19 @@ func Test_New(t *testing.T) { //nolint:funlen,gocognit,gocyclo err bool } - jsonMarshalFunc := func(w io.Writer, body interface{}) error { + jsonMarshalFunc := func(_ io.Writer, _ interface{}) error { return nil } - notFoundView := func(ctx *RequestCtx) error { + notFoundView := func(_ *RequestCtx) error { return nil } - methodNotAllowedView := func(ctx *RequestCtx) error { + methodNotAllowedView := func(_ *RequestCtx) error { return nil } panicErr := errors.New("error") panicView := func(ctx *RequestCtx, err interface{}) { - ctx.Error(panicErr.Error(), fasthttp.StatusInternalServerError) + ctx.Error(fmt.Sprint(err), fasthttp.StatusInternalServerError) } tests := []struct { @@ -210,10 +210,10 @@ func Test_New(t *testing.T) { //nolint:funlen,gocognit,gocyclo func Test_newFasthttpServer(t *testing.T) { //nolint:funlen cfg := Config{ Name: "test", - HeaderReceived: func(header *fasthttp.RequestHeader) fasthttp.RequestConfig { + HeaderReceived: func(_ *fasthttp.RequestHeader) fasthttp.RequestConfig { return fasthttp.RequestConfig{} }, - ContinueHandler: func(header *fasthttp.RequestHeader) bool { return true }, + ContinueHandler: func(_ *fasthttp.RequestHeader) bool { return true }, Concurrency: rand.Int(), // nolint:gosec ReadBufferSize: rand.Int(), // nolint:gosec WriteBufferSize: rand.Int(), // nolint:gosec @@ -244,7 +244,7 @@ func Test_newFasthttpServer(t *testing.T) { //nolint:funlen ConnState: func(net.Conn, fasthttp.ConnState) {}, Logger: testLog, TLSConfig: &tls.Config{ServerName: "test", MinVersion: tls.VersionTLS13}, - FormValueFunc: func(ctx *fasthttp.RequestCtx, key string) []byte { return nil }, + FormValueFunc: func(_ *fasthttp.RequestCtx, _ string) []byte { return nil }, } srv := newFasthttpServer(cfg) @@ -576,7 +576,7 @@ func TestAtreugo_NewVirtualHost(t *testing.T) { //nolint:funlen conflictHosts := []conflictArgs{ { hostnames: []string{hostname}, - wantErrMsg: fmt.Sprintf("a router is already registered for virtual host: %s", hostname), + wantErrMsg: "a router is already registered for virtual host: " + hostname, }, { hostnames: []string{}, @@ -584,7 +584,7 @@ func TestAtreugo_NewVirtualHost(t *testing.T) { //nolint:funlen }, { hostnames: []string{"localhost", "localhost"}, - wantErrMsg: fmt.Sprintf("a router is already registered for virtual host: %s", hostname), + wantErrMsg: "a router is already registered for virtual host: " + hostname, }, } @@ -679,13 +679,13 @@ func TestAtreugo_ShutdownWithContext(t *testing.T) { // Benchmarks. func Benchmark_Handler(b *testing.B) { s := New(testConfig) - s.GET("/plaintext", func(ctx *RequestCtx) error { return nil }) - s.GET("/json", func(ctx *RequestCtx) error { return nil }) - s.GET("/db", func(ctx *RequestCtx) error { return nil }) - s.GET("/queries", func(ctx *RequestCtx) error { return nil }) - s.GET("/cached-worlds", func(ctx *RequestCtx) error { return nil }) - s.GET("/fortunes", func(ctx *RequestCtx) error { return nil }) - s.GET("/updates", func(ctx *RequestCtx) error { return nil }) + s.GET("/plaintext", func(_ *RequestCtx) error { return nil }) + s.GET("/json", func(_ *RequestCtx) error { return nil }) + s.GET("/db", func(_ *RequestCtx) error { return nil }) + s.GET("/queries", func(_ *RequestCtx) error { return nil }) + s.GET("/cached-worlds", func(_ *RequestCtx) error { return nil }) + s.GET("/fortunes", func(_ *RequestCtx) error { return nil }) + s.GET("/updates", func(_ *RequestCtx) error { return nil }) ctx := new(fasthttp.RequestCtx) ctx.Request.Header.SetMethod("GET") diff --git a/listener_unix_test.go b/listener_unix_test.go index 1b2311b..8a68e1d 100644 --- a/listener_unix_test.go +++ b/listener_unix_test.go @@ -107,7 +107,7 @@ func TestAtreugo_getListener(t *testing.T) { // nolint:funlen,gocognit s := New(tt.args) if tt.name == "UnixChmodError" { - s.cfg.chmodUnixSocketFunc = func(addr string) error { + s.cfg.chmodUnixSocketFunc = func(_ string) error { return errors.New("chmod error") } } diff --git a/path_test.go b/path_test.go index b319b00..ad2fd77 100644 --- a/path_test.go +++ b/path_test.go @@ -51,7 +51,7 @@ func newTestPath() *Path { router: testRouter(), method: fasthttp.MethodGet, url: "/test", - view: func(ctx *RequestCtx) error { return nil }, + view: func(_ *RequestCtx) error { return nil }, } } @@ -98,10 +98,8 @@ func TestPath_UseAfter(t *testing.T) { func TestPath_UseFinal(t *testing.T) { finalMiddlewareFns := []FinalMiddleware{ - func(ctx *RequestCtx) { - }, - func(ctx *RequestCtx) { - }, + func(_ *RequestCtx) {}, + func(_ *RequestCtx) {}, } p := newTestPath() diff --git a/response_test.go b/response_test.go index 600a770..0f41b6f 100644 --- a/response_test.go +++ b/response_test.go @@ -72,10 +72,10 @@ func TestJSONResponse(t *testing.T) { //nolint:funlen { name: "CustomJSONMarshalFunc", args: args{ - body: make(chan int), + body: "my custom response", statusCode: 200, jsonMarshalFunc: func(w io.Writer, value interface{}) error { - _, err := w.Write([]byte("my custom response")) + _, err := w.Write([]byte(fmt.Sprint(value))) return err // nolint:wrapcheck }, diff --git a/router_test.go b/router_test.go index ed61066..c30d249 100644 --- a/router_test.go +++ b/router_test.go @@ -149,7 +149,7 @@ func TestRouter_newRouter(t *testing.T) { } func TestRouter_mutable(t *testing.T) { - handler := func(ctx *fasthttp.RequestCtx) {} + handler := func(_ *fasthttp.RequestCtx) {} r := testRouter() r.router.GET("/", handler) @@ -178,7 +178,7 @@ func TestRouter_buildMiddlewares(t *testing.T) { middleware1 := func(ctx *RequestCtx) error { return ctx.Next() } middleware2 := func(ctx *RequestCtx) error { return ctx.Next() } middleware3 := func(ctx *RequestCtx) error { return ctx.Next() } - middleware4 := func(ctx *RequestCtx) {} + middleware4 := func(_ *RequestCtx) {} middle := Middlewares{ Before: []Middleware{middleware1, middleware2}, @@ -276,7 +276,7 @@ func TestRouter_handlerExecutionChain(t *testing.T) { //nolint:funlen return ctx.Next() }) - s.UseFinal(func(ctx *RequestCtx) { + s.UseFinal(func(_ *RequestCtx) { index++ callOrder["globalFinal"] = index }) @@ -294,14 +294,14 @@ func TestRouter_handlerExecutionChain(t *testing.T) { //nolint:funlen return ctx.Next() }, skipMiddlewareGroup) - v1.UseFinal(func(ctx *RequestCtx) { + v1.UseFinal(func(_ *RequestCtx) { index++ callOrder["groupFinal"] = index }) v1.SkipMiddlewares(skipMiddlewareGlobal) - v1.Path(method, url, func(ctx *RequestCtx) error { + v1.Path(method, url, func(_ *RequestCtx) error { viewCalled = true return nil @@ -315,7 +315,7 @@ func TestRouter_handlerExecutionChain(t *testing.T) { //nolint:funlen callOrder["viewAfter"] = index return ctx.Next() - }).UseFinal(func(ctx *RequestCtx) { + }).UseFinal(func(_ *RequestCtx) { index++ callOrder["viewFinal"] = index }).SkipMiddlewares(skipMiddlewareGroup) @@ -425,7 +425,7 @@ func TestRouter_handler(t *testing.T) { //nolint:funlen,maintidx }, } final := []FinalMiddleware{ - func(ctx *RequestCtx) { + func(_ *RequestCtx) { handlerCounter.finalMiddlewares++ }, } @@ -446,7 +446,7 @@ func TestRouter_handler(t *testing.T) { //nolint:funlen,maintidx }, }, Final: []FinalMiddleware{ - func(ctx *RequestCtx) { + func(_ *RequestCtx) { handlerCounter.finalViewMiddlewares++ }, }, @@ -511,7 +511,7 @@ func TestRouter_handler(t *testing.T) { //nolint:funlen,maintidx { name: "ViewError", args: args{ - viewFn: func(ctx *RequestCtx) error { + viewFn: func(_ *RequestCtx) error { return err }, before: before, @@ -583,7 +583,7 @@ func TestRouter_handler(t *testing.T) { //nolint:funlen,maintidx }, }, Final: []FinalMiddleware{ - func(ctx *RequestCtx) { + func(_ *RequestCtx) { handlerCounter.finalViewMiddlewares++ }, }, @@ -625,7 +625,7 @@ func TestRouter_handler(t *testing.T) { //nolint:funlen,maintidx }, }, Final: []FinalMiddleware{ - func(ctx *RequestCtx) { + func(_ *RequestCtx) { handlerCounter.finalViewMiddlewares++ }, }, @@ -677,7 +677,7 @@ func TestRouter_handler(t *testing.T) { //nolint:funlen,maintidx args: args{ viewFn: viewFn, before: []Middleware{ - func(ctx *RequestCtx) error { + func(_ *RequestCtx) error { handlerCounter.beforeMiddlewares++ return nil @@ -785,7 +785,7 @@ func TestRouter_handlePath(t *testing.T) { router: r, method: fasthttp.MethodGet, url: "/test", - view: func(ctx *RequestCtx) error { return nil }, + view: func(_ *RequestCtx) error { return nil }, middlewares: Middlewares{}, withTimeout: true, timeout: 1 * time.Millisecond, @@ -867,8 +867,8 @@ func TestRouter_NewGroupPath(t *testing.T) { func TestRouter_ListPaths(t *testing.T) { server := New(testConfig) - server.Path("GET", "/foo", func(ctx *RequestCtx) error { return nil }) - server.Path("GET", "/bar", func(ctx *RequestCtx) error { return nil }) + server.Path("GET", "/foo", func(_ *RequestCtx) error { return nil }) + server.Path("GET", "/bar", func(_ *RequestCtx) error { return nil }) static := server.NewGroupPath("/static") static.Static("/buzz", "./docs") @@ -924,7 +924,7 @@ func TestRouter_SkipMiddlewares(t *testing.T) { func TestRouter_Path_Shortcuts(t *testing.T) { //nolint:funlen path := "/" - viewFn := func(ctx *RequestCtx) error { return nil } + viewFn := func(_ *RequestCtx) error { return nil } r := testRouter() @@ -1111,6 +1111,7 @@ func TestRouter_StaticCustom(t *testing.T) { //nolint:funlen }) ctx := new(fasthttp.RequestCtx) + handler, _ := r.router.Lookup("GET", tt.want.routerPath, ctx) if handler == nil { t.Fatal("Static files is not configured") @@ -1187,7 +1188,7 @@ func TestRouter_Path(t *testing.T) { //nolint:funlen return nil } - testNetHTTPHandler := func(w http.ResponseWriter, r *http.Request) { + testNetHTTPHandler := func(w http.ResponseWriter, _ *http.Request) { fmt.Fprintf(w, "Test") } testMuxHandler := http.NewServeMux() @@ -1337,7 +1338,7 @@ func TestRouter_Path(t *testing.T) { //nolint:funlen func Benchmark_handler(b *testing.B) { r := testRouter() - h := r.handler(func(ctx *RequestCtx) error { return nil }, Middlewares{}) + h := r.handler(func(_ *RequestCtx) error { return nil }, Middlewares{}) ctx := new(fasthttp.RequestCtx) @@ -1350,7 +1351,7 @@ func Benchmark_handler(b *testing.B) { func Benchmark_RouterHandler(b *testing.B) { r := testRouter() - r.GET("/", func(ctx *RequestCtx) error { return nil }) + r.GET("/", func(_ *RequestCtx) error { return nil }) ctx := new(fasthttp.RequestCtx) ctx.Request.Header.SetMethod("GET") diff --git a/utils_test.go b/utils_test.go index 520c2f2..3eb3092 100644 --- a/utils_test.go +++ b/utils_test.go @@ -46,7 +46,7 @@ func Test_viewToHandler(t *testing.T) { called := false err := errors.New("error") - view := func(ctx *RequestCtx) error { + view := func(_ *RequestCtx) error { called = true return err @@ -84,8 +84,8 @@ func Test_isEqual(t *testing.T) { } func Test_middlewaresInclude(t *testing.T) { - fnIncluded := func(ctx *RequestCtx) error { return nil } - fnNotIncluded := func(ctx *RequestCtx) error { return nil } + fnIncluded := func(_ *RequestCtx) error { return nil } + fnNotIncluded := func(_ *RequestCtx) error { return nil } ms := []Middleware{fnIncluded} if !middlewaresInclude(ms, fnIncluded) { @@ -98,8 +98,8 @@ func Test_middlewaresInclude(t *testing.T) { } func Test_appendMiddlewares(t *testing.T) { - fn := func(ctx *RequestCtx) error { return nil } - fnSkip := func(ctx *RequestCtx) error { return nil } + fn := func(_ *RequestCtx) error { return nil } + fnSkip := func(_ *RequestCtx) error { return nil } dst := []Middleware{} src := []Middleware{fn, fnSkip}