Skip to content

Commit

Permalink
Merge branch 'main' into v3-params
Browse files Browse the repository at this point in the history
  • Loading branch information
dozheiny authored Mar 18, 2024
2 parents 0230b4e + 82070cb commit 57d29b7
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 35 deletions.
14 changes: 4 additions & 10 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,17 +72,12 @@ linters-settings:

gocritic:
# TODO: Uncomment the following lines
# enabled-tags:
# - diagnostic
enabled-tags:
- diagnostic
# - style
# - performance
# - experimental
# - opinionated
disabled-checks:
- ifElseChain # TODO: Do not disable
# - hugeParam
# - rangeExprCopy
# - rangeValCopy
settings:
captLocal:
paramsOnly: false
Expand Down Expand Up @@ -195,6 +190,8 @@ linters-settings:
disabled: true
- name: unchecked-type-assertion
disabled: true # TODO: Do not disable
- name: unhandled-error
arguments: ['bytes\.Buffer\.Write']

stylecheck:
checks:
Expand All @@ -217,9 +214,6 @@ linters-settings:

testifylint:
enable-all: true
# TODO: Do not disable any options
disable:
- go-require

testpackage:
skip-regexp: "^$"
Expand Down
3 changes: 1 addition & 2 deletions app.go
Original file line number Diff line number Diff line change
Expand Up @@ -988,8 +988,7 @@ func (app *App) Test(req *http.Request, timeout ...time.Duration) (*http.Respons

type disableLogger struct{}

func (*disableLogger) Printf(_ string, _ ...any) {
// fmt.Println(fmt.Sprintf(format, args...))
func (*disableLogger) Printf(string, ...any) {
}

func (app *App) init() *App {
Expand Down
2 changes: 0 additions & 2 deletions app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1316,13 +1316,11 @@ func Test_App_Group(t *testing.T) {
resp, err := app.Test(httptest.NewRequest(MethodPost, "/test/v1/", nil))
require.NoError(t, err, "app.Test(req)")
require.Equal(t, 200, resp.StatusCode, "Status code")
// require.Equal(t, "/test/v1", resp.Header.Get("Location"), "Location")

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

func Test_App_Route(t *testing.T) {
Expand Down
1 change: 0 additions & 1 deletion bind_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,6 @@ func Benchmark_Bind_Query_Comma(b *testing.B) {
}
c.Request().SetBody([]byte(``))
c.Request().Header.SetContentType("")
// c.Request().URI().SetQueryString("id=1&name=tom&hobby=basketball&hobby=football")
c.Request().URI().SetQueryString("id=1&name=tom&hobby=basketball,football")
q := new(Query)
b.ReportAllocs()
Expand Down
7 changes: 4 additions & 3 deletions client/hooks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,11 +183,12 @@ func Test_Parser_Request_URL(t *testing.T) {

flag1, flag2, flag3 := false, false, false
for _, v := range values["bar"] {
if v == "foo1" {
switch v {
case "foo1":
flag1 = true
} else if v == "foo2" {
case "foo2":
flag2 = true
} else if v == "foo" {
case "foo":
flag3 = true
}
}
Expand Down
1 change: 1 addition & 0 deletions ctx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1436,6 +1436,7 @@ func Test_Ctx_Parsers(t *testing.T) {
})
t.Run("ParamsParser", func(t *testing.T) {
t.Skip("ParamsParser is not ready for v3")
//nolint:gocritic // TODO: uncomment
// t.Parallel()
// withValues(t, func(c Ctx, testStruct *TestStruct) error {
// c.route = &Route{Params: []string{"name", "name2", "class", "class2"}}
Expand Down
10 changes: 5 additions & 5 deletions helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ func readContent(rf io.ReaderFrom, name string) (int64, error) {
// quoteString escape special characters in a given string
func (app *App) quoteString(raw string) string {
bb := bytebufferpool.Get()
// quoted := string(fasthttp.AppendQuotedArg(bb.B, getBytes(raw)))
quoted := app.getString(fasthttp.AppendQuotedArg(bb.B, app.getBytes(raw)))
bytebufferpool.Put(bb)
return quoted
Expand Down Expand Up @@ -462,13 +461,14 @@ func getOffer(header []byte, isAccepted func(spec, offer string, specParams head
// Get specificity
var specificity int
// check for wildcard this could be a mime */* or a wildcard character *
if string(spec) == "*/*" || string(spec) == "*" {
switch {
case string(spec) == "*/*" || string(spec) == "*":
specificity = 1
} else if bytes.HasSuffix(spec, []byte("/*")) {
case bytes.HasSuffix(spec, []byte("/*")):
specificity = 2
} else if bytes.IndexByte(spec, '/') != -1 {
case bytes.IndexByte(spec, '/') != -1:
specificity = 3
} else {
default:
specificity = 4
}

Expand Down
9 changes: 5 additions & 4 deletions middleware/keyauth/keyauth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,16 @@ func TestAuthSources(t *testing.T) {
require.NoError(t, err)

// setup the apikey for the different auth schemes
if authSource == "header" {
switch authSource {
case "header":
req.Header.Set(test.authTokenName, test.APIKey)
} else if authSource == "cookie" {
case "cookie":
req.Header.Set("Cookie", test.authTokenName+"="+test.APIKey)
} else if authSource == "query" || authSource == "form" {
case "query", "form":
q := req.URL.Query()
q.Add(test.authTokenName, test.APIKey)
req.URL.RawQuery = q.Encode()
} else if authSource == "param" {
case "param":
r := req.URL.Path
r += url.PathEscape(test.APIKey)
req.URL.Path = r
Expand Down
7 changes: 4 additions & 3 deletions middleware/logger/default_logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,12 @@ func defaultLoggerInstance(c fiber.Ctx, data *Data, cfg Config) error {
var err error
// Loop over template parts execute dynamic parts and add fixed parts to the buffer
for i, logFunc := range data.LogFuncChain {
if logFunc == nil {
switch {
case logFunc == nil:
buf.Write(data.TemplateChain[i])
} else if data.TemplateChain[i] == nil {
case data.TemplateChain[i] == nil:
_, err = logFunc(buf, c, data, "")
} else {
default:
_, err = logFunc(buf, c, data, utils.UnsafeString(data.TemplateChain[i]))
}
if err != nil {
Expand Down
12 changes: 7 additions & 5 deletions middleware/session/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,18 +72,20 @@ func (s *Store) Get(c fiber.Ctx) (*Session, error) {
if loadData {
raw, err := s.Storage.Get(id)
// Unmarshal if we found data
if raw != nil && err == nil {
switch {
case err != nil:
return nil, err

case raw != nil:
mux.Lock()
defer mux.Unlock()
_, _ = sess.byteBuffer.Write(raw) // Ignore error, this will never fail
sess.byteBuffer.Write(raw)
encCache := gob.NewDecoder(sess.byteBuffer)
err := encCache.Decode(&sess.data.Data)
if err != nil {
return nil, fmt.Errorf("failed to decode session data: %w", err)
}
} else if err != nil {
return nil, err
} else {
default:
// both raw and err is nil, which means id is not in the storage
sess.fresh = true
}
Expand Down

0 comments on commit 57d29b7

Please sign in to comment.