Skip to content

Commit 388cb79

Browse files
committed
chore: update branch with master
2 parents 9c0980e + 8c3f81e commit 388cb79

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+929
-753
lines changed

.github/workflows/benchmark.yml

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ permissions:
1414
deployments: write
1515
# contents permission to update benchmark contents in gh-pages branch
1616
contents: write
17+
# allow posting comments to pull request
18+
pull-requests: write
1719

1820
name: Benchmark
1921
jobs:

.golangci.yml

-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ linters-settings:
101101
govet:
102102
enable-all: true
103103
disable:
104-
- fieldalignment
105104
- shadow
106105

107106
grouper:

Makefile

+5
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,8 @@ longtest:
5151
.PHONY: tidy
5252
tidy:
5353
go mod tidy -v
54+
55+
## betteralign: 📐 Optimize alignment of fields in structs
56+
.PHONY: betteralign
57+
betteralign:
58+
go run github.com/dkorunic/betteralign/cmd/betteralign@latest -test_files -generated_files -apply ./...

addon/retry/exponential_backoff_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ import (
1111
func Test_ExponentialBackoff_Retry(t *testing.T) {
1212
t.Parallel()
1313
tests := []struct {
14-
name string
14+
expErr error
1515
expBackoff *ExponentialBackoff
1616
f func() error
17-
expErr error
17+
name string
1818
}{
1919
{
2020
name: "With default values - successful",

app.go

+19-19
Original file line numberDiff line numberDiff line change
@@ -80,29 +80,16 @@ type ErrorHandler = func(Ctx, error) error
8080

8181
// Error represents an error that occurred while handling a request.
8282
type Error struct {
83-
Code int `json:"code"`
8483
Message string `json:"message"`
84+
Code int `json:"code"`
8585
}
8686

8787
// App denotes the Fiber application.
8888
type App struct {
89-
mutex sync.Mutex
90-
// Route stack divided by HTTP methods
91-
stack [][]*Route
92-
// Route stack divided by HTTP methods and route prefixes
93-
treeStack []map[string][]*Route
94-
// contains the information if the route stack has been changed to build the optimized tree
95-
routesRefreshed bool
96-
// Amount of registered routes
97-
routesCount uint32
98-
// Amount of registered handlers
99-
handlersCount uint32
10089
// Ctx pool
10190
pool sync.Pool
10291
// Fasthttp server
10392
server *fasthttp.Server
104-
// App config
105-
config Config
10693
// Converts string to a byte slice
10794
getBytes func(s string) (b []byte)
10895
// Converts byte slice to a string
@@ -113,24 +100,37 @@ type App struct {
113100
latestRoute *Route
114101
// newCtxFunc
115102
newCtxFunc func(app *App) CustomCtx
116-
// custom binders
117-
customBinders []CustomBinder
118103
// TLS handler
119104
tlsHandler *TLSHandler
120105
// Mount fields
121106
mountFields *mountFields
122-
// Indicates if the value was explicitly configured
123-
configured Config
107+
// Route stack divided by HTTP methods
108+
stack [][]*Route
109+
// Route stack divided by HTTP methods and route prefixes
110+
treeStack []map[string][]*Route
111+
// custom binders
112+
customBinders []CustomBinder
124113
// customConstraints is a list of external constraints
125114
customConstraints []CustomConstraint
126115
// sendfiles stores configurations for handling ctx.SendFile operations
127116
sendfiles []*sendFileStore
117+
// App config
118+
config Config
119+
// Indicates if the value was explicitly configured
120+
configured Config
128121
// sendfilesMutex is a mutex used for sendfile operations
129122
sendfilesMutex sync.RWMutex
123+
mutex sync.Mutex
124+
// Amount of registered routes
125+
routesCount uint32
126+
// Amount of registered handlers
127+
handlersCount uint32
128+
// contains the information if the route stack has been changed to build the optimized tree
129+
routesRefreshed bool
130130
}
131131

132132
// Config is a struct holding the server settings.
133-
type Config struct {
133+
type Config struct { //nolint:govet // Aligning the struct fields is not necessary. betteralign:ignore
134134
// Enables the "Server: value" HTTP header.
135135
//
136136
// Default: ""

bind_test.go

+20-20
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ func Test_Bind_Query(t *testing.T) {
2626
c := app.AcquireCtx(&fasthttp.RequestCtx{})
2727

2828
type Query struct {
29-
ID int
3029
Name string
3130
Hobby []string
31+
ID int
3232
}
3333
c.Request().SetBody([]byte(``))
3434
c.Request().Header.SetContentType("")
@@ -53,14 +53,14 @@ func Test_Bind_Query(t *testing.T) {
5353
require.Empty(t, empty.Hobby)
5454

5555
type Query2 struct {
56-
Bool bool
57-
ID int
5856
Name string
5957
Hobby string
6058
FavouriteDrinks []string
6159
Empty []string
6260
Alloc []string
6361
No []int64
62+
ID int
63+
Bool bool
6464
}
6565

6666
c.Request().URI().SetQueryString("id=1&name=tom&hobby=basketball,football&favouriteDrinks=milo,coke,pepsi&alloc=&no=1")
@@ -237,8 +237,8 @@ func Test_Bind_Query_Schema(t *testing.T) {
237237
require.Equal(t, "nested.age is empty", c.Bind().Query(q2).Error())
238238

239239
type Node struct {
240-
Value int `query:"val,required"`
241240
Next *Node `query:"next,required"`
241+
Value int `query:"val,required"`
242242
}
243243
c.Request().URI().SetQueryString("val=1&next.val=3")
244244
n := new(Node)
@@ -292,9 +292,9 @@ func Test_Bind_Header(t *testing.T) {
292292
c := app.AcquireCtx(&fasthttp.RequestCtx{})
293293

294294
type Header struct {
295-
ID int
296295
Name string
297296
Hobby []string
297+
ID int
298298
}
299299
c.Request().SetBody([]byte(``))
300300
c.Request().Header.SetContentType("")
@@ -318,14 +318,14 @@ func Test_Bind_Header(t *testing.T) {
318318
require.Empty(t, empty.Hobby)
319319

320320
type Header2 struct {
321-
Bool bool
322-
ID int
323321
Name string
324322
Hobby string
325323
FavouriteDrinks []string
326324
Empty []string
327325
Alloc []string
328326
No []int64
327+
ID int
328+
Bool bool
329329
}
330330

331331
c.Request().Header.Add("id", "2")
@@ -502,8 +502,8 @@ func Test_Bind_Header_Schema(t *testing.T) {
502502
require.Equal(t, "Nested.age is empty", c.Bind().Header(h2).Error())
503503

504504
type Node struct {
505-
Value int `header:"Val,required"`
506505
Next *Node `header:"Next,required"`
506+
Value int `header:"Val,required"`
507507
}
508508
c.Request().Header.Add("Val", "1")
509509
c.Request().Header.Add("Next.Val", "3")
@@ -533,9 +533,9 @@ func Test_Bind_RespHeader(t *testing.T) {
533533
c := app.AcquireCtx(&fasthttp.RequestCtx{})
534534

535535
type Header struct {
536-
ID int
537536
Name string
538537
Hobby []string
538+
ID int
539539
}
540540
c.Request().SetBody([]byte(``))
541541
c.Request().Header.SetContentType("")
@@ -559,14 +559,14 @@ func Test_Bind_RespHeader(t *testing.T) {
559559
require.Empty(t, empty.Hobby)
560560

561561
type Header2 struct {
562-
Bool bool
563-
ID int
564562
Name string
565563
Hobby string
566564
FavouriteDrinks []string
567565
Empty []string
568566
Alloc []string
569567
No []int64
568+
ID int
569+
Bool bool
570570
}
571571

572572
c.Response().Header.Add("id", "2")
@@ -635,9 +635,9 @@ func Benchmark_Bind_Query(b *testing.B) {
635635
c := app.AcquireCtx(&fasthttp.RequestCtx{})
636636

637637
type Query struct {
638-
ID int
639638
Name string
640639
Hobby []string
640+
ID int
641641
}
642642
c.Request().SetBody([]byte(``))
643643
c.Request().Header.SetContentType("")
@@ -708,9 +708,9 @@ func Benchmark_Bind_Query_Comma(b *testing.B) {
708708
c := app.AcquireCtx(&fasthttp.RequestCtx{})
709709

710710
type Query struct {
711-
ID int
712711
Name string
713712
Hobby []string
713+
ID int
714714
}
715715
c.Request().SetBody([]byte(``))
716716
c.Request().Header.SetContentType("")
@@ -732,9 +732,9 @@ func Benchmark_Bind_Header(b *testing.B) {
732732
c := app.AcquireCtx(&fasthttp.RequestCtx{})
733733

734734
type ReqHeader struct {
735-
ID int
736735
Name string
737736
Hobby []string
737+
ID int
738738
}
739739
c.Request().SetBody([]byte(``))
740740
c.Request().Header.SetContentType("")
@@ -782,9 +782,9 @@ func Benchmark_Bind_RespHeader(b *testing.B) {
782782
c := app.AcquireCtx(&fasthttp.RequestCtx{})
783783

784784
type ReqHeader struct {
785-
ID int
786785
Name string
787786
Hobby []string
787+
ID int
788788
}
789789
c.Request().SetBody([]byte(``))
790790
c.Request().Header.SetContentType("")
@@ -1252,9 +1252,9 @@ func Test_Bind_Cookie(t *testing.T) {
12521252
c := app.AcquireCtx(&fasthttp.RequestCtx{})
12531253

12541254
type Cookie struct {
1255-
ID int
12561255
Name string
12571256
Hobby []string
1257+
ID int
12581258
}
12591259
c.Request().SetBody([]byte(``))
12601260
c.Request().Header.SetContentType("")
@@ -1278,14 +1278,14 @@ func Test_Bind_Cookie(t *testing.T) {
12781278
require.Empty(t, empty.Hobby)
12791279

12801280
type Cookie2 struct {
1281-
Bool bool
1282-
ID int
12831281
Name string
12841282
Hobby string
12851283
FavouriteDrinks []string
12861284
Empty []string
12871285
Alloc []string
12881286
No []int64
1287+
ID int
1288+
Bool bool
12891289
}
12901290

12911291
c.Request().Header.SetCookie("id", "2")
@@ -1463,8 +1463,8 @@ func Test_Bind_Cookie_Schema(t *testing.T) {
14631463
require.Equal(t, "Nested.Age is empty", c.Bind().Cookie(h2).Error())
14641464

14651465
type Node struct {
1466-
Value int `cookie:"Val,required"`
14671466
Next *Node `cookie:"Next,required"`
1467+
Value int `cookie:"Val,required"`
14681468
}
14691469
c.Request().Header.SetCookie("Val", "1")
14701470
c.Request().Header.SetCookie("Next.Val", "3")
@@ -1495,9 +1495,9 @@ func Benchmark_Bind_Cookie(b *testing.B) {
14951495
c := app.AcquireCtx(&fasthttp.RequestCtx{})
14961496

14971497
type Cookie struct {
1498-
ID int
14991498
Name string
15001499
Hobby []string
1500+
ID int
15011501
}
15021502
c.Request().SetBody([]byte(``))
15031503
c.Request().Header.SetContentType("")

binder/mapping.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ import (
1212

1313
// ParserConfig form decoder config for SetParserDecoder
1414
type ParserConfig struct {
15-
IgnoreUnknownKeys bool
1615
SetAliasTag string
1716
ParserType []ParserType
17+
IgnoreUnknownKeys bool
1818
ZeroEmpty bool
1919
}
2020

0 commit comments

Comments
 (0)