Skip to content

Commit 57d29b7

Browse files
authored
Merge branch 'main' into v3-params
2 parents 0230b4e + 82070cb commit 57d29b7

File tree

10 files changed

+31
-35
lines changed

10 files changed

+31
-35
lines changed

.golangci.yml

+4-10
Original file line numberDiff line numberDiff line change
@@ -72,17 +72,12 @@ linters-settings:
7272

7373
gocritic:
7474
# TODO: Uncomment the following lines
75-
# enabled-tags:
76-
# - diagnostic
75+
enabled-tags:
76+
- diagnostic
7777
# - style
7878
# - performance
7979
# - experimental
8080
# - opinionated
81-
disabled-checks:
82-
- ifElseChain # TODO: Do not disable
83-
# - hugeParam
84-
# - rangeExprCopy
85-
# - rangeValCopy
8681
settings:
8782
captLocal:
8883
paramsOnly: false
@@ -195,6 +190,8 @@ linters-settings:
195190
disabled: true
196191
- name: unchecked-type-assertion
197192
disabled: true # TODO: Do not disable
193+
- name: unhandled-error
194+
arguments: ['bytes\.Buffer\.Write']
198195

199196
stylecheck:
200197
checks:
@@ -217,9 +214,6 @@ linters-settings:
217214

218215
testifylint:
219216
enable-all: true
220-
# TODO: Do not disable any options
221-
disable:
222-
- go-require
223217

224218
testpackage:
225219
skip-regexp: "^$"

app.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -988,8 +988,7 @@ func (app *App) Test(req *http.Request, timeout ...time.Duration) (*http.Respons
988988

989989
type disableLogger struct{}
990990

991-
func (*disableLogger) Printf(_ string, _ ...any) {
992-
// fmt.Println(fmt.Sprintf(format, args...))
991+
func (*disableLogger) Printf(string, ...any) {
993992
}
994993

995994
func (app *App) init() *App {

app_test.go

-2
Original file line numberDiff line numberDiff line change
@@ -1316,13 +1316,11 @@ func Test_App_Group(t *testing.T) {
13161316
resp, err := app.Test(httptest.NewRequest(MethodPost, "/test/v1/", nil))
13171317
require.NoError(t, err, "app.Test(req)")
13181318
require.Equal(t, 200, resp.StatusCode, "Status code")
1319-
// require.Equal(t, "/test/v1", resp.Header.Get("Location"), "Location")
13201319

13211320
api.Get("/users", dummyHandler)
13221321
resp, err = app.Test(httptest.NewRequest(MethodGet, "/test/v1/UsErS", nil))
13231322
require.NoError(t, err, "app.Test(req)")
13241323
require.Equal(t, 200, resp.StatusCode, "Status code")
1325-
// require.Equal(t, "/test/v1/users", resp.Header.Get("Location"), "Location")
13261324
}
13271325

13281326
func Test_App_Route(t *testing.T) {

bind_test.go

-1
Original file line numberDiff line numberDiff line change
@@ -714,7 +714,6 @@ func Benchmark_Bind_Query_Comma(b *testing.B) {
714714
}
715715
c.Request().SetBody([]byte(``))
716716
c.Request().Header.SetContentType("")
717-
// c.Request().URI().SetQueryString("id=1&name=tom&hobby=basketball&hobby=football")
718717
c.Request().URI().SetQueryString("id=1&name=tom&hobby=basketball,football")
719718
q := new(Query)
720719
b.ReportAllocs()

client/hooks_test.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -183,11 +183,12 @@ func Test_Parser_Request_URL(t *testing.T) {
183183

184184
flag1, flag2, flag3 := false, false, false
185185
for _, v := range values["bar"] {
186-
if v == "foo1" {
186+
switch v {
187+
case "foo1":
187188
flag1 = true
188-
} else if v == "foo2" {
189+
case "foo2":
189190
flag2 = true
190-
} else if v == "foo" {
191+
case "foo":
191192
flag3 = true
192193
}
193194
}

ctx_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -1436,6 +1436,7 @@ func Test_Ctx_Parsers(t *testing.T) {
14361436
})
14371437
t.Run("ParamsParser", func(t *testing.T) {
14381438
t.Skip("ParamsParser is not ready for v3")
1439+
//nolint:gocritic // TODO: uncomment
14391440
// t.Parallel()
14401441
// withValues(t, func(c Ctx, testStruct *TestStruct) error {
14411442
// c.route = &Route{Params: []string{"name", "name2", "class", "class2"}}

helpers.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ func readContent(rf io.ReaderFrom, name string) (int64, error) {
9494
// quoteString escape special characters in a given string
9595
func (app *App) quoteString(raw string) string {
9696
bb := bytebufferpool.Get()
97-
// quoted := string(fasthttp.AppendQuotedArg(bb.B, getBytes(raw)))
9897
quoted := app.getString(fasthttp.AppendQuotedArg(bb.B, app.getBytes(raw)))
9998
bytebufferpool.Put(bb)
10099
return quoted
@@ -462,13 +461,14 @@ func getOffer(header []byte, isAccepted func(spec, offer string, specParams head
462461
// Get specificity
463462
var specificity int
464463
// check for wildcard this could be a mime */* or a wildcard character *
465-
if string(spec) == "*/*" || string(spec) == "*" {
464+
switch {
465+
case string(spec) == "*/*" || string(spec) == "*":
466466
specificity = 1
467-
} else if bytes.HasSuffix(spec, []byte("/*")) {
467+
case bytes.HasSuffix(spec, []byte("/*")):
468468
specificity = 2
469-
} else if bytes.IndexByte(spec, '/') != -1 {
469+
case bytes.IndexByte(spec, '/') != -1:
470470
specificity = 3
471-
} else {
471+
default:
472472
specificity = 4
473473
}
474474

middleware/keyauth/keyauth_test.go

+5-4
Original file line numberDiff line numberDiff line change
@@ -89,15 +89,16 @@ func TestAuthSources(t *testing.T) {
8989
require.NoError(t, err)
9090

9191
// setup the apikey for the different auth schemes
92-
if authSource == "header" {
92+
switch authSource {
93+
case "header":
9394
req.Header.Set(test.authTokenName, test.APIKey)
94-
} else if authSource == "cookie" {
95+
case "cookie":
9596
req.Header.Set("Cookie", test.authTokenName+"="+test.APIKey)
96-
} else if authSource == "query" || authSource == "form" {
97+
case "query", "form":
9798
q := req.URL.Query()
9899
q.Add(test.authTokenName, test.APIKey)
99100
req.URL.RawQuery = q.Encode()
100-
} else if authSource == "param" {
101+
case "param":
101102
r := req.URL.Path
102103
r += url.PathEscape(test.APIKey)
103104
req.URL.Path = r

middleware/logger/default_logger.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,12 @@ func defaultLoggerInstance(c fiber.Ctx, data *Data, cfg Config) error {
108108
var err error
109109
// Loop over template parts execute dynamic parts and add fixed parts to the buffer
110110
for i, logFunc := range data.LogFuncChain {
111-
if logFunc == nil {
111+
switch {
112+
case logFunc == nil:
112113
buf.Write(data.TemplateChain[i])
113-
} else if data.TemplateChain[i] == nil {
114+
case data.TemplateChain[i] == nil:
114115
_, err = logFunc(buf, c, data, "")
115-
} else {
116+
default:
116117
_, err = logFunc(buf, c, data, utils.UnsafeString(data.TemplateChain[i]))
117118
}
118119
if err != nil {

middleware/session/store.go

+7-5
Original file line numberDiff line numberDiff line change
@@ -72,18 +72,20 @@ func (s *Store) Get(c fiber.Ctx) (*Session, error) {
7272
if loadData {
7373
raw, err := s.Storage.Get(id)
7474
// Unmarshal if we found data
75-
if raw != nil && err == nil {
75+
switch {
76+
case err != nil:
77+
return nil, err
78+
79+
case raw != nil:
7680
mux.Lock()
7781
defer mux.Unlock()
78-
_, _ = sess.byteBuffer.Write(raw) // Ignore error, this will never fail
82+
sess.byteBuffer.Write(raw)
7983
encCache := gob.NewDecoder(sess.byteBuffer)
8084
err := encCache.Decode(&sess.data.Data)
8185
if err != nil {
8286
return nil, fmt.Errorf("failed to decode session data: %w", err)
8387
}
84-
} else if err != nil {
85-
return nil, err
86-
} else {
88+
default:
8789
// both raw and err is nil, which means id is not in the storage
8890
sess.fresh = true
8991
}

0 commit comments

Comments
 (0)