Skip to content

Commit

Permalink
🧹 v3 (chore): fix linter warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
efectn committed Aug 5, 2023
1 parent 75bb02b commit 44acb06
Show file tree
Hide file tree
Showing 11 changed files with 44 additions and 40 deletions.
2 changes: 1 addition & 1 deletion ctx_interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ type Ctx interface {
SendStream(stream io.Reader, size ...int) error

// Set sets the response's HTTP header field to the specified key, value.
Set(key string, val string)
Set(key, val string)

// Subdomains returns a string slice of subdomains in the domain name of the request.
// The subdomain offset, which defaults to 2, is used for determining the beginning of the subdomain segments.
Expand Down
24 changes: 12 additions & 12 deletions ctx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,7 @@ func Benchmark_Ctx_Format(b *testing.B) {
// go test -v -run=^$ -bench=Benchmark_Ctx_Format_HTML -benchmem -count=4
func Benchmark_Ctx_Format_HTML(b *testing.B) {
app := New()
c := app.NewCtx(&fasthttp.RequestCtx{}) //nolint:errcheck, forcetypeassert // not needed
c := app.NewCtx(&fasthttp.RequestCtx{})

c.Request().Header.Set("Accept", "text/html")
b.ReportAllocs()
Expand All @@ -633,7 +633,7 @@ func Benchmark_Ctx_Format_HTML(b *testing.B) {
// go test -v -run=^$ -bench=Benchmark_Ctx_Format_JSON -benchmem -count=4
func Benchmark_Ctx_Format_JSON(b *testing.B) {
app := New()
c := app.NewCtx(&fasthttp.RequestCtx{}) //nolint:errcheck, forcetypeassert // not needed
c := app.NewCtx(&fasthttp.RequestCtx{})

c.Request().Header.Set("Accept", "application/json")
b.ReportAllocs()
Expand All @@ -650,7 +650,7 @@ func Benchmark_Ctx_Format_JSON(b *testing.B) {
// go test -v -run=^$ -bench=Benchmark_Ctx_Format_XML -benchmem -count=4
func Benchmark_Ctx_Format_XML(b *testing.B) {
app := New()
c := app.NewCtx(&fasthttp.RequestCtx{}) //nolint:errcheck, forcetypeassert // not needed
c := app.NewCtx(&fasthttp.RequestCtx{})

c.Request().Header.Set("Accept", "application/xml")
b.ReportAllocs()
Expand Down Expand Up @@ -1679,7 +1679,7 @@ func Test_Ctx_Params_Case_Sensitive(t *testing.T) {
// go test -v -run=^$ -bench=Benchmark_Ctx_Params -benchmem -count=4
func Benchmark_Ctx_Params(b *testing.B) {
app := New()
c := app.NewCtx(&fasthttp.RequestCtx{}).(*DefaultCtx)
c := app.NewCtx(&fasthttp.RequestCtx{}).(*DefaultCtx) //nolint:errcheck, forcetypeassert // not needed

c.route = &Route{
Params: []string{
Expand Down Expand Up @@ -2412,7 +2412,7 @@ func Test_Ctx_JSONP(t *testing.T) {
// go test -v -run=^$ -bench=Benchmark_Ctx_JSONP -benchmem -count=4
func Benchmark_Ctx_JSONP(b *testing.B) {
app := New()
c := app.NewCtx(&fasthttp.RequestCtx{}).(*DefaultCtx)
c := app.NewCtx(&fasthttp.RequestCtx{}).(*DefaultCtx) //nolint:errcheck, forcetypeassert // not needed

type SomeStruct struct {
Name string
Expand All @@ -2437,7 +2437,7 @@ func Benchmark_Ctx_JSONP(b *testing.B) {
func Test_Ctx_XML(t *testing.T) {
t.Parallel()
app := New()
c := app.NewCtx(&fasthttp.RequestCtx{}).(*DefaultCtx)
c := app.NewCtx(&fasthttp.RequestCtx{}).(*DefaultCtx) //nolint:errcheck, forcetypeassert // not needed

require.True(t, c.JSON(complex(1, 1)) != nil)

Expand Down Expand Up @@ -2470,7 +2470,7 @@ func Test_Ctx_XML(t *testing.T) {
// go test -run=^$ -bench=Benchmark_Ctx_XML -benchmem -count=4
func Benchmark_Ctx_XML(b *testing.B) {
app := New()
c := app.NewCtx(&fasthttp.RequestCtx{}).(*DefaultCtx)
c := app.NewCtx(&fasthttp.RequestCtx{}).(*DefaultCtx) //nolint:errcheck, forcetypeassert // not needed
type SomeStruct struct {
Name string `xml:"Name"`
Age uint8 `xml:"Age"`
Expand Down Expand Up @@ -2509,7 +2509,7 @@ func Test_Ctx_Links(t *testing.T) {
// go test -v -run=^$ -bench=Benchmark_Ctx_Links -benchmem -count=4
func Benchmark_Ctx_Links(b *testing.B) {
app := New()
c := app.NewCtx(&fasthttp.RequestCtx{}).(*DefaultCtx)
c := app.NewCtx(&fasthttp.RequestCtx{}).(*DefaultCtx) //nolint:errcheck, forcetypeassert // not needed

b.ReportAllocs()
b.ResetTimer()
Expand Down Expand Up @@ -2935,7 +2935,7 @@ func Benchmark_Ctx_Render_Engine(b *testing.B) {
// go test -v -run=^$ -bench=Benchmark_Ctx_Get_Location_From_Route -benchmem -count=4
func Benchmark_Ctx_Get_Location_From_Route(b *testing.B) {
app := New()
c := app.NewCtx(&fasthttp.RequestCtx{}).(*DefaultCtx)
c := app.NewCtx(&fasthttp.RequestCtx{}).(*DefaultCtx) //nolint:errcheck, forcetypeassert // not needed

app.Get("/user/:name", func(c Ctx) error {
return c.SendString(c.Params("name"))
Expand Down Expand Up @@ -3235,7 +3235,7 @@ func Benchmark_Ctx_Type(b *testing.B) {
// go test -v -run=^$ -bench=Benchmark_Ctx_Type_Charset -benchmem -count=4
func Benchmark_Ctx_Type_Charset(b *testing.B) {
app := New()
c := app.NewCtx(&fasthttp.RequestCtx{}).(*DefaultCtx)
c := app.NewCtx(&fasthttp.RequestCtx{}).(*DefaultCtx) //nolint:errcheck, forcetypeassert // not needed

b.ReportAllocs()
b.ResetTimer()
Expand All @@ -3260,7 +3260,7 @@ func Test_Ctx_Vary(t *testing.T) {
// go test -v -run=^$ -bench=Benchmark_Ctx_Vary -benchmem -count=4
func Benchmark_Ctx_Vary(b *testing.B) {
app := New()
c := app.NewCtx(&fasthttp.RequestCtx{}).(*DefaultCtx)
c := app.NewCtx(&fasthttp.RequestCtx{}).(*DefaultCtx) //nolint:errcheck, forcetypeassert // not needed

b.ReportAllocs()
b.ResetTimer()
Expand Down Expand Up @@ -3313,7 +3313,7 @@ func Test_Ctx_Writef(t *testing.T) {
// go test -v -run=^$ -bench=Benchmark_Ctx_Writef -benchmem -count=4
func Benchmark_Ctx_Writef(b *testing.B) {
app := New()
c := app.NewCtx(&fasthttp.RequestCtx{}).(*DefaultCtx)
c := app.NewCtx(&fasthttp.RequestCtx{}).(*DefaultCtx) //nolint:errcheck, forcetypeassert // not needed

world := "World!"
b.ReportAllocs()
Expand Down
6 changes: 3 additions & 3 deletions listen.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ func (app *App) printMessages(cfg ListenConfig, ln net.Listener) {
}

// prepareListenData create an slice of ListenData
func (app *App) prepareListenData(addr string, isTLS bool, cfg ListenConfig) ListenData { //revive:disable-line:flag-parameter // Accepting a bool param named isTLS if fine here
func (*App) prepareListenData(addr string, isTLS bool, cfg ListenConfig) ListenData { //revive:disable-line:flag-parameter // Accepting a bool param named isTLS if fine here
host, port := parseAddr(addr)
if host == "" {
if cfg.ListenerNetwork == NetworkTCP6 {
Expand All @@ -311,7 +311,7 @@ func (app *App) prepareListenData(addr string, isTLS bool, cfg ListenConfig) Lis
}

// startupMessage prepares the startup message with the handler number, port, address and other information
func (app *App) startupMessage(addr string, enableTLS bool, pids string, cfg ListenConfig) { //nolint:revive TODO: Check CertKeyFile instead of control-flag.
func (app *App) startupMessage(addr string, isTLS bool, pids string, cfg ListenConfig) { //nolint: revive // Accepting a bool param named isTLS if fine here
// ignore child processes
if IsChild() {
return
Expand All @@ -330,7 +330,7 @@ func (app *App) startupMessage(addr string, enableTLS bool, pids string, cfg Lis
}

scheme := schemeHTTP
if enableTLS {
if isTLS {
scheme = schemeHTTPS
}

Expand Down
2 changes: 0 additions & 2 deletions middleware/filesystem/filesystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,6 @@ func New(config ...Config) fiber.Handler {
}

if err != nil {
fmt.Print("test")
fmt.Print(err)
if errors.Is(err, fs.ErrNotExist) {
return c.Status(fiber.StatusNotFound).Next()
}
Expand Down
1 change: 0 additions & 1 deletion middleware/logger/default_logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ func defaultLoggerInstance(c fiber.Ctx, data *Data, cfg Config) error {
bytebufferpool.Put(buf)

return nil

}

// run something before returning the handler
Expand Down
1 change: 0 additions & 1 deletion middleware/logger/logger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ func Test_Logger_ErrorTimeZone(t *testing.T) {
type fakeOutput int

func (o *fakeOutput) Write([]byte) (int, error) {
fmt.Print(*o)
*o++
return 0, errors.New("fake output")
}
Expand Down
4 changes: 2 additions & 2 deletions middleware/proxy/proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ func Test_Proxy_Do_WithRedirect(t *testing.T) {
return Do(c, "https://google.com")
})

resp, err1 := app.Test(httptest.NewRequest(fiber.MethodGet, "/test", nil))
resp, err1 := app.Test(httptest.NewRequest(fiber.MethodGet, "/test", nil), 1500)
require.Equal(t, nil, err1)
body, err := io.ReadAll(resp.Body)
require.NoError(t, err)
Expand Down Expand Up @@ -447,7 +447,7 @@ func Test_Proxy_DoRedirects_TooManyRedirects(t *testing.T) {
return DoRedirects(c, "http://google.com", 0)
})

resp, err1 := app.Test(httptest.NewRequest(fiber.MethodGet, "/test", nil))
resp, err1 := app.Test(httptest.NewRequest(fiber.MethodGet, "/test", nil), 1500)
require.Equal(t, nil, err1)
body, err := io.ReadAll(resp.Body)
require.NoError(t, err)
Expand Down
5 changes: 3 additions & 2 deletions redirect.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func (r *Redirect) Status(code int) *Redirect {
// They will be sent as a cookie.
// You can get them by using: Redirect().Messages(), Redirect().Message()
// Note: You must use escape char before using ',' and ':' chars to avoid wrong parsing.
func (r *Redirect) With(key string, value string) *Redirect {
func (r *Redirect) With(key, value string) *Redirect {
r.messages = append(r.messages, key+CookieDataAssigner+value)

return r
Expand Down Expand Up @@ -290,9 +290,10 @@ func (r *Redirect) setFlash() {
r.c.ClearCookie(FlashCookieName)
}

func parseMessage(raw string) (key string, value string) {
func parseMessage(raw string) (string, string) { //nolint: revive // not necessary
if i := findNextNonEscapedCharsetPosition(raw, []byte(CookieDataAssigner)); i != -1 {
return RemoveEscapeChar(raw[:i]), RemoveEscapeChar(raw[i+1:])
}

return RemoveEscapeChar(raw), ""
}
22 changes: 11 additions & 11 deletions redirect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ func Test_Redirect_Route_WithFlashMessages(t *testing.T) {
return c.SendString("user")
}).Name("user")

c := app.NewCtx(&fasthttp.RequestCtx{}).(*DefaultCtx)
c := app.NewCtx(&fasthttp.RequestCtx{}).(*DefaultCtx) //nolint:errcheck, forcetypeassert // not needed

err := c.Redirect().With("success", "1").With("message", "test").Route("user")
require.NoError(t, err)
Expand All @@ -201,7 +201,7 @@ func Test_Redirect_Route_WithOldInput(t *testing.T) {
return c.SendString("user")
}).Name("user")

c := app.NewCtx(&fasthttp.RequestCtx{}).(*DefaultCtx)
c := app.NewCtx(&fasthttp.RequestCtx{}).(*DefaultCtx) //nolint:errcheck, forcetypeassert // not needed

c.Request().URI().SetQueryString("id=1&name=tom")
err := c.Redirect().With("success", "1").With("message", "test").WithInput().Route("user")
Expand Down Expand Up @@ -229,7 +229,7 @@ func Test_Redirect_setFlash(t *testing.T) {
return c.SendString("user")
}).Name("user")

c := app.NewCtx(&fasthttp.RequestCtx{}).(*DefaultCtx)
c := app.NewCtx(&fasthttp.RequestCtx{}).(*DefaultCtx) //nolint:errcheck, forcetypeassert // not needed

c.Request().Header.Set(HeaderCookie, "fiber_flash=success:1,message:test,old_input_data_name:tom,old_input_data_id:1")

Expand Down Expand Up @@ -336,7 +336,7 @@ func Benchmark_Redirect_Route(b *testing.B) {
return c.JSON(c.Params("name"))
}).Name("user")

c := app.NewCtx(&fasthttp.RequestCtx{}).(*DefaultCtx)
c := app.NewCtx(&fasthttp.RequestCtx{}).(*DefaultCtx) //nolint:errcheck, forcetypeassert // not needed

b.ReportAllocs()
b.ResetTimer()
Expand All @@ -360,7 +360,7 @@ func Benchmark_Redirect_Route_WithQueries(b *testing.B) {
return c.JSON(c.Params("name"))
}).Name("user")

c := app.NewCtx(&fasthttp.RequestCtx{}).(*DefaultCtx)
c := app.NewCtx(&fasthttp.RequestCtx{}).(*DefaultCtx) //nolint:errcheck, forcetypeassert // not needed

b.ReportAllocs()
b.ResetTimer()
Expand Down Expand Up @@ -389,7 +389,7 @@ func Benchmark_Redirect_Route_WithFlashMessages(b *testing.B) {
return c.SendString("user")
}).Name("user")

c := app.NewCtx(&fasthttp.RequestCtx{}).(*DefaultCtx)
c := app.NewCtx(&fasthttp.RequestCtx{}).(*DefaultCtx) //nolint:errcheck, forcetypeassert // not needed

b.ReportAllocs()
b.ResetTimer()
Expand All @@ -415,7 +415,7 @@ func Benchmark_Redirect_setFlash(b *testing.B) {
return c.SendString("user")
}).Name("user")

c := app.NewCtx(&fasthttp.RequestCtx{}).(*DefaultCtx)
c := app.NewCtx(&fasthttp.RequestCtx{}).(*DefaultCtx) //nolint:errcheck, forcetypeassert // not needed

c.Request().Header.Set(HeaderCookie, "fiber_flash=success:1,message:test,old_input_data_name:tom,old_input_data_id:1")

Expand Down Expand Up @@ -444,7 +444,7 @@ func Benchmark_Redirect_Messages(b *testing.B) {
return c.SendString("user")
}).Name("user")

c := app.NewCtx(&fasthttp.RequestCtx{}).(*DefaultCtx)
c := app.NewCtx(&fasthttp.RequestCtx{}).(*DefaultCtx) //nolint:errcheck, forcetypeassert // not needed

c.Request().Header.Set(HeaderCookie, "fiber_flash=success:1,message:test,old_input_data_name:tom,old_input_data_id:1")
c.Redirect().setFlash()
Expand All @@ -469,7 +469,7 @@ func Benchmark_Redirect_OldInputs(b *testing.B) {
return c.SendString("user")
}).Name("user")

c := app.NewCtx(&fasthttp.RequestCtx{}).(*DefaultCtx)
c := app.NewCtx(&fasthttp.RequestCtx{}).(*DefaultCtx) //nolint:errcheck, forcetypeassert // not needed

c.Request().Header.Set(HeaderCookie, "fiber_flash=success:1,message:test,old_input_data_name:tom,old_input_data_id:1")
c.Redirect().setFlash()
Expand All @@ -494,7 +494,7 @@ func Benchmark_Redirect_Message(b *testing.B) {
return c.SendString("user")
}).Name("user")

c := app.NewCtx(&fasthttp.RequestCtx{}).(*DefaultCtx)
c := app.NewCtx(&fasthttp.RequestCtx{}).(*DefaultCtx) //nolint:errcheck, forcetypeassert // not needed

c.Request().Header.Set(HeaderCookie, "fiber_flash=success:1,message:test,old_input_data_name:tom,old_input_data_id:1")
c.Redirect().setFlash()
Expand All @@ -519,7 +519,7 @@ func Benchmark_Redirect_OldInput(b *testing.B) {
return c.SendString("user")
}).Name("user")

c := app.NewCtx(&fasthttp.RequestCtx{}).(*DefaultCtx)
c := app.NewCtx(&fasthttp.RequestCtx{}).(*DefaultCtx) //nolint:errcheck, forcetypeassert // not needed

c.Request().Header.Set(HeaderCookie, "fiber_flash=success:1,message:test,old_input_data_name:tom,old_input_data_id:1")
c.Redirect().setFlash()
Expand Down
13 changes: 10 additions & 3 deletions router.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func (r *Route) match(detectionPath, path string, params *[maxParams]string) boo
return false
}

func (app *App) nextCustom(c CustomCtx) (bool, error) {
func (app *App) nextCustom(c CustomCtx) (bool, error) { //nolint: unparam // bool param might be useful for testing
// Get stack length
tree, ok := app.treeStack[c.getMethodINT()][c.getTreePath()]
if !ok {
Expand Down Expand Up @@ -204,10 +204,17 @@ func (app *App) next(c *DefaultCtx) (bool, error) {
func (app *App) requestHandler(rctx *fasthttp.RequestCtx) {
// Handler for default ctxs
var c CustomCtx
var ok bool
if app.newCtxFunc != nil {
c = app.AcquireCtx().(CustomCtx)
c, ok = app.AcquireCtx().(CustomCtx)
if !ok {
panic(fmt.Errorf("failed to type-assert to CustomCtx"))
}
} else {
c = app.AcquireCtx().(*DefaultCtx)
c, ok = app.AcquireCtx().(*DefaultCtx)
if !ok {
panic(fmt.Errorf("failed to type-assert to *DefaultCtx"))
}
}
c.Reset(rctx)
defer app.ReleaseCtx(c)
Expand Down
4 changes: 2 additions & 2 deletions router_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,7 @@ func Benchmark_Router_Next(b *testing.B) {
var res bool
var err error

c := app.NewCtx(request).(*DefaultCtx)
c := app.NewCtx(request).(*DefaultCtx) //nolint:errcheck, forcetypeassert // not needed

b.ResetTimer()
for n := 0; n < b.N; n++ {
Expand Down Expand Up @@ -799,7 +799,7 @@ func Benchmark_Router_Github_API(b *testing.B) {
for n := 0; n < b.N; n++ {
c.URI().SetPath(routesFixture.TestRoutes[i].Path)

ctx := app.AcquireCtx().(*DefaultCtx)
ctx := app.AcquireCtx().(*DefaultCtx) //nolint:errcheck, forcetypeassert // not needed
ctx.Reset(c)

match, err = app.next(ctx)
Expand Down

0 comments on commit 44acb06

Please sign in to comment.