Skip to content

Commit 0bf0353

Browse files
committed
Merge remote-tracking branch 'origin/main'
2 parents 47e9c8f + bc4c920 commit 0bf0353

35 files changed

+1101
-577
lines changed

.github/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ We **listen** to our users in [issues](https://github.com/gofiber/fiber/issues),
124124

125125
## ⚠️ Limitations
126126

127-
- Due to Fiber's usage of unsafe, the library may not always be compatible with the latest Go version. Fiber v3 has been tested with Go version 1.23.
127+
- Due to Fiber's usage of unsafe, the library may not always be compatible with the latest Go version. Fiber v3 has been tested with Go version 1.23 or higher.
128128
- Fiber is not compatible with net/http interfaces. This means you will not be able to use projects like gqlgen, go-swagger, or any others which are part of the net/http ecosystem.
129129

130130
## 👀 Examples
@@ -708,7 +708,7 @@ List of externally hosted middleware modules and maintained by the [Fiber team](
708708
| :------------------------------------------------ | :-------------------------------------------------------------------------------------------------------------------- |
709709
| [contrib](https://github.com/gofiber/contrib) | Third-party middlewares |
710710
| [storage](https://github.com/gofiber/storage) | Premade storage drivers that implement the Storage interface, designed to be used with various Fiber middlewares. |
711-
| [template](https://github.com/gofiber/template) | This package contains 9 template engines that can be used with Fiber `v3`. Go version 1.23 or higher is required. |
711+
| [template](https://github.com/gofiber/template) | This package contains 9 template engines that can be used with Fiber. |
712712

713713
## 🕶️ Awesome List
714714

.github/codecov.yml

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# ignore files or directories to be scanned by codecov
2+
ignore:
3+
- "./docs/"
4+
5+
coverage:
6+
status:
7+
project:
8+
default:
9+
threshold: 0.5%

.github/workflows/test.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
unit:
1616
strategy:
1717
matrix:
18-
go-version: [1.23.x]
18+
go-version: [1.23.x, 1.24.x]
1919
platform: [ubuntu-latest, windows-latest, macos-latest, macos-13]
2020
runs-on: ${{ matrix.platform }}
2121
steps:

app.go

+41-30
Original file line numberDiff line numberDiff line change
@@ -750,75 +750,75 @@ func (app *App) Use(args ...any) Router {
750750
return app
751751
}
752752

753-
app.register([]string{methodUse}, prefix, nil, nil, handlers...)
753+
app.register([]string{methodUse}, prefix, nil, handlers...)
754754
}
755755

756756
return app
757757
}
758758

759759
// Get registers a route for GET methods that requests a representation
760760
// of the specified resource. Requests using GET should only retrieve data.
761-
func (app *App) Get(path string, handler Handler, middleware ...Handler) Router {
762-
return app.Add([]string{MethodGet}, path, handler, middleware...)
761+
func (app *App) Get(path string, handler Handler, handlers ...Handler) Router {
762+
return app.Add([]string{MethodGet}, path, handler, handlers...)
763763
}
764764

765765
// Head registers a route for HEAD methods that asks for a response identical
766766
// to that of a GET request, but without the response body.
767-
func (app *App) Head(path string, handler Handler, middleware ...Handler) Router {
768-
return app.Add([]string{MethodHead}, path, handler, middleware...)
767+
func (app *App) Head(path string, handler Handler, handlers ...Handler) Router {
768+
return app.Add([]string{MethodHead}, path, handler, handlers...)
769769
}
770770

771771
// Post registers a route for POST methods that is used to submit an entity to the
772772
// specified resource, often causing a change in state or side effects on the server.
773-
func (app *App) Post(path string, handler Handler, middleware ...Handler) Router {
774-
return app.Add([]string{MethodPost}, path, handler, middleware...)
773+
func (app *App) Post(path string, handler Handler, handlers ...Handler) Router {
774+
return app.Add([]string{MethodPost}, path, handler, handlers...)
775775
}
776776

777777
// Put registers a route for PUT methods that replaces all current representations
778778
// of the target resource with the request payload.
779-
func (app *App) Put(path string, handler Handler, middleware ...Handler) Router {
780-
return app.Add([]string{MethodPut}, path, handler, middleware...)
779+
func (app *App) Put(path string, handler Handler, handlers ...Handler) Router {
780+
return app.Add([]string{MethodPut}, path, handler, handlers...)
781781
}
782782

783783
// Delete registers a route for DELETE methods that deletes the specified resource.
784-
func (app *App) Delete(path string, handler Handler, middleware ...Handler) Router {
785-
return app.Add([]string{MethodDelete}, path, handler, middleware...)
784+
func (app *App) Delete(path string, handler Handler, handlers ...Handler) Router {
785+
return app.Add([]string{MethodDelete}, path, handler, handlers...)
786786
}
787787

788788
// Connect registers a route for CONNECT methods that establishes a tunnel to the
789789
// server identified by the target resource.
790-
func (app *App) Connect(path string, handler Handler, middleware ...Handler) Router {
791-
return app.Add([]string{MethodConnect}, path, handler, middleware...)
790+
func (app *App) Connect(path string, handler Handler, handlers ...Handler) Router {
791+
return app.Add([]string{MethodConnect}, path, handler, handlers...)
792792
}
793793

794794
// Options registers a route for OPTIONS methods that is used to describe the
795795
// communication options for the target resource.
796-
func (app *App) Options(path string, handler Handler, middleware ...Handler) Router {
797-
return app.Add([]string{MethodOptions}, path, handler, middleware...)
796+
func (app *App) Options(path string, handler Handler, handlers ...Handler) Router {
797+
return app.Add([]string{MethodOptions}, path, handler, handlers...)
798798
}
799799

800800
// Trace registers a route for TRACE methods that performs a message loop-back
801801
// test along the path to the target resource.
802-
func (app *App) Trace(path string, handler Handler, middleware ...Handler) Router {
803-
return app.Add([]string{MethodTrace}, path, handler, middleware...)
802+
func (app *App) Trace(path string, handler Handler, handlers ...Handler) Router {
803+
return app.Add([]string{MethodTrace}, path, handler, handlers...)
804804
}
805805

806806
// Patch registers a route for PATCH methods that is used to apply partial
807807
// modifications to a resource.
808-
func (app *App) Patch(path string, handler Handler, middleware ...Handler) Router {
809-
return app.Add([]string{MethodPatch}, path, handler, middleware...)
808+
func (app *App) Patch(path string, handler Handler, handlers ...Handler) Router {
809+
return app.Add([]string{MethodPatch}, path, handler, handlers...)
810810
}
811811

812812
// Add allows you to specify multiple HTTP methods to register a route.
813-
func (app *App) Add(methods []string, path string, handler Handler, middleware ...Handler) Router {
814-
app.register(methods, path, nil, handler, middleware...)
813+
func (app *App) Add(methods []string, path string, handler Handler, handlers ...Handler) Router {
814+
app.register(methods, path, nil, append([]Handler{handler}, handlers...)...)
815815

816816
return app
817817
}
818818

819819
// All will register the handler on all HTTP methods
820-
func (app *App) All(path string, handler Handler, middleware ...Handler) Router {
821-
return app.Add(app.config.RequestMethods, path, handler, middleware...)
820+
func (app *App) All(path string, handler Handler, handlers ...Handler) Router {
821+
return app.Add(app.config.RequestMethods, path, handler, handlers...)
822822
}
823823

824824
// Group is used for Routes with common prefix to define a new sub-router with optional middleware.
@@ -828,7 +828,7 @@ func (app *App) All(path string, handler Handler, middleware ...Handler) Router
828828
func (app *App) Group(prefix string, handlers ...Handler) Router {
829829
grp := &Group{Prefix: prefix, app: app}
830830
if len(handlers) > 0 {
831-
app.register([]string{methodUse}, prefix, grp, nil, handlers...)
831+
app.register([]string{methodUse}, prefix, grp, handlers...)
832832
}
833833
if err := app.hooks.executeOnGroupHooks(*grp); err != nil {
834834
panic(err)
@@ -894,6 +894,13 @@ func (app *App) HandlersCount() uint32 {
894894
//
895895
// Make sure the program doesn't exit and waits instead for Shutdown to return.
896896
//
897+
// Important: app.Listen() must be called in a separate goroutine, otherwise shutdown hooks will not work
898+
// as Listen() is a blocking operation. Example:
899+
//
900+
// go app.Listen(":3000")
901+
// // ...
902+
// app.Shutdown()
903+
//
897904
// Shutdown does not close keepalive connections so its recommended to set ReadTimeout to something else than 0.
898905
func (app *App) Shutdown() error {
899906
return app.ShutdownWithContext(context.Background())
@@ -918,17 +925,21 @@ func (app *App) ShutdownWithTimeout(timeout time.Duration) error {
918925
//
919926
// ShutdownWithContext does not close keepalive connections so its recommended to set ReadTimeout to something else than 0.
920927
func (app *App) ShutdownWithContext(ctx context.Context) error {
921-
if app.hooks != nil {
922-
// TODO: check should be defered?
923-
app.hooks.executeOnShutdownHooks()
924-
}
925-
926928
app.mutex.Lock()
927929
defer app.mutex.Unlock()
930+
931+
var err error
932+
928933
if app.server == nil {
929934
return ErrNotRunning
930935
}
931-
return app.server.ShutdownWithContext(ctx)
936+
937+
// Execute the Shutdown hook
938+
app.hooks.executeOnPreShutdownHooks()
939+
defer app.hooks.executeOnPostShutdownHooks(err)
940+
941+
err = app.server.ShutdownWithContext(ctx)
942+
return err
932943
}
933944

934945
// Server returns the underlying fasthttp server

0 commit comments

Comments
 (0)