* feat: support for starting devtime dependencies in an abstract manner
* feat: support for starting devtime dependencies in an abstract manner
* fix: spell
* fix: lint
* fix: markdown lint
* fix: b.Helper
* fix: lint spell
* fix: field padding
* chore: protect the usage of dev dependencies with the "dev" build tag
* fix: error message
* docs: fix type name
* fix: mock context cancellation
* docs: simpler
* fix: lint unused receiver
* fix: handle error in benchmarks
* lint: remove build tag
* fix: wrap error
* fix: lint
* fix: explain why lint exclusion
* chore: best effort while terminating dependencies
* gix: lintern name
* fix: reduce flakiness in tests
* chore: get dependency state for logs
* chore: protect dev time tests and benchmarks under build tag
* chore: add build tag in more places
* fix: more conservative context cancellation timeout in tests
* chore: remove build tags
* chore: rename to Services
* fix: update tests
* fix: lint
* fix: lint
* fix: apply coderrabit suggestion
* chore: add more unit tests
* chore: add more unit tests
* chore: refactor tests
* fix: avoid control flags in tests
* chore: consistent error message in start
* chore: simplify error logic
* chore: remove flag coupling
* chore: simplify benchmarks
* chore: add corerabbit suggetion
* fix: wording
* chore: log error on service termination
* docs: wording
* fix: typo in error message
* fix: wording
* fix: panic on startup error
* chore: store started services separately, so that we can terminate them properly
* docs: update example
* fix: use context provider instead of storing the context
* chore: use require.Empty
* fix: no tabs in docs
* chore: move field for better alignment
* docs: do not use interface as method receiver
* docs: proper usage of JSON bind
* fix: use startup context for bootstrap log
* chore: move happy path to the left
* fix: use configured consistently
* chore: terminate started services in reverse order
* fix: consistent access to the config context
* chore: test names and benchmarks location
* chore: benchmark refinement
* chore: store the services into the global State
* chore: add functions to access the Services in the state
* chore: hex-encode the hashes
* chore: consistent var name for services
* chore: non racey service initialisation
* fix: wrong range iteration in service keys
* fix: use inline
* chore: more tests for the generics functions for services
* chore: add benchmarks for service functions
* fix: benchmarks refactor was wrong
* fix. refine error message
* fix: do not cause overhead in newState, instead pre-calculate the prefix hash at init
* chore: simplify hashing
* chore: use smaller, and testable function for initServices
* chore: initialize services in the app.init
* chore: init services before blocking the app init
* Revert "chore: init services before blocking the app init"
This reverts commit bb67cf6380cb71ad5ae4ab4807cdfbf0c7eafa1b.
* chore: move happy path to the left at initServices
* fix: register shutdown hooks for services after app's mutext is unlocked
---------
Co-authored-by: Juan Calderon-Perez <835733+gaby@users.noreply.github.com>
* feat: Add All method to Bind
This commit introduces a new `All` method to the `Bind` struct, enabling the binding of request data from multiple sources (URI parameters, body, query parameters, headers, and cookies) into a single struct.
The `All` method iterates through the available binding sources, applying them in a predefined precedence order. It merges the values from each source into the output struct, only updating fields that are currently unset.
Changes:
- Added `All` method to `Bind` struct.
- Added `mergeStruct` helper function to merge struct values.
- Added `isZero` helper function to check if a value is zero.
- Added a test case for the `All` method in `bind_test.go` to validate its functionality.
* feat: Enhance Bind.All with comprehensive testing and configuration
The changes include:
- Added `RequestConfig` struct to encapsulate request configuration (ContentType, Body, Headers, Cookies, Query).
- Implemented `ApplyTo` method on `RequestConfig` to apply the configuration to the context.
- Created multiple test cases for `Bind.All` covering successful binding, missing fields, overriding query parameters, and form binding.
- Added a test case `Test_Bind_All_Uri_Precedence` to validate the precedence of URI parameters.
- Added benchmark test `BenchmarkBind_All` to measure the performance of the `Bind.All` method.
- Refactored the `TestBind_All` to use the new `RequestConfig` and assertion libraries.
* fix: Correct form binding in Test_Bind_All
* refactor: Improve Bind.All test and struct field ordering
- Reordered fields in `RequestConfig` and `User` structs for field alignment
- Updated `Test_Bind_All` to use `require.NoError` for more robust error checking.
- Corrected header key casing in `Test_Bind_All` to `X-User-Role` to match the struct tag.
- Added `t.Parallel()` to the test function to enable parallel test execution.
* feat: Document Bind.All function in API documentation
This commit adds documentation for the `Bind.All` function to the API documentation.
The documentation includes:
- A description of the function's purpose and precedence order for binding data from different sources (URI, body, query, headers, cookies).
* docs: lint Bind.All documentation
* fix: Update parameter tags from 'param' to 'uri' in bind_test.go
* fix: Update parameter tags from 'param' to 'uri' in bind.md
* test: Replace assert with require in bind_test.go
* feat: Add support for unified binding with defined precedence order in whats_new.md
---------
Co-authored-by: RW <rene@gofiber.io>
* Set default redirect response status to 303 SeeOther
Closes#3405
In some browsers, redirect status 302 Found sometimes is used to change
the HTTP verb of the response from what the user set to what was used in
the request. Changing to 303 SeeOther in the default works more like
expected: it defaults to GET and can be overriden by the user.
* Add tests to Redirect default status change.
* Update docs.
* Fix remaining tests to reflect redirect 303 status as the new default. Reflect that in docs/whats_new.md
* Update redirect_test.go
* Fix code review hints
---------
Co-authored-by: Juan Calderon-Perez <835733+gaby@users.noreply.github.com>
Co-authored-by: René <rene@gofiber.io>
* Force the use of terminal colors via config option
* docs: add example for forcing terminal colors in logger middleware
* test: add benchmarks for logger middleware with forced colors
* Add ForceColors field to 'whats new'
* Show example in 'whats new'
Revert "🔥 feat: Add Context Support to RequestID Middleware (#3200)"
This reverts commit f725ded92bac13e773f92ff478e1a461c160abd3.
Co-authored-by: Juan Calderon-Perez <835733+gaby@users.noreply.github.com>
* feat(logger): Add predefined log formats
This commit introduces predefined log formats for the logger middleware, enhancing its flexibility and ease of use. Users can now specify formats like "common", "combined", and "json" in addition to the default format.
Changes:
- Added a `format.go` file to store predefined log format constants.
- Updated `config.go` to include documentation for the `Format` configuration option, explaining the available placeholders and predefined formats.
- Modified `logger.go` to utilize the predefined formats based on the `Format` configuration.
- Added a new test case `Test_Logger_CLF` in `logger_test.go` to verify the "common" log format.
* feat(logger): Use predefined formats and fix default format
This commit updates the logger middleware to utilize the predefined log formats introduced in a previous commit. It also fixes the default format to use the `FormatDefault` constant.
Changes:
- Updated `config.go` to use `FormatDefault` constant for the default format.
- Updated `default_logger.go` to use `FormatDefault` constant for the default format.
- Added new test cases in `logger_test.go` to verify the "common", "combined" and "json" log formats.
- Updated `format.go` to add newline character to the end of the default format.
* feat(logger): Document and exemplify predefined formats
* fix(logger): Improve test assertions based on golangci-lint
* docs(logger): Improve documentation and formatting logger.md based on markdownlint-cli2
* docs(logger): Improve documentation based on markdownlint-cli2
* fix(logger): Improve combined and JSON format tests
* feat(logger): Add ECS log format
* feat(logger): Add CustomFormat option
This commit introduces a `CustomFormat` option to the `Config` struct, allowing users to specify a predefined format (like "common", "combined", "json", or "ecs")
* feat(logger): Add ECS log format to examples and config
* docs(logger): Update examples in whats_new.md
* feat(logger): Remove CustomFormat option and renamed Format consts
- Removed `CustomFormat` field from `Config`.
- Removed `LoggerConfig` map.
- Rename predefined formats constants.
* docs(logger): Update documentation and examples after format refactor
---------
Co-authored-by: Juan Calderon-Perez <835733+gaby@users.noreply.github.com>
* 🔥 feat: add Req and Res interfaces
Split the existing Ctx API into two separate APIs for Requests and
Responses. There are two goals to this change:
1. Reduce cognitive load by making it more obvious whether a Ctx method
interacts with the request or the response.
2. Increase API parity with Express.
* fix(req,res): several issues
* Sprinkle in calls to Req() and Res() to a few unit tests
* Fix improper initialization caught by ^
* Add a few missing methods
* docs: organize Ctx methods by request and response
* feat(req,res): sync more missed methods
---------
Co-authored-by: Juan Calderon-Perez <835733+gaby@users.noreply.github.com>
* fix handler order in routing
#3312
* fix handler order in routing
#3312
* fix handler order in routing
#3312
* fix handler order in routing
#3312
* fix handler order in routing
#3312
---------
Co-authored-by: Juan Calderon-Perez <835733+gaby@users.noreply.github.com>
* feat: Optimize ShutdownWithContext method in app.go
- Reorder mutex lock acquisition to the start of the function
- Early return if server is not running
- Use defer for executing shutdown hooks
- Simplify nil check for hooks
- Remove TODO comment
This commit improves the readability, robustness, and execution order
of the shutdown process. It ensures consistent state throughout the
shutdown and guarantees hook execution even in error cases.
* feat: Enhance ShutdownWithContext test for improved reliability
- Add shutdown hook verification
- Implement better synchronization with channels
- Improve error handling and assertions
- Adjust timeouts for more consistent results
- Add server state check after shutdown attempt
- Include comments explaining expected behavior
This commit improves the comprehensiveness and reliability of the
ShutdownWithContext test, ensuring proper verification of shutdown
hooks, timeout behavior, and server state during long-running requests.
* 📚 Doc: update the docs to explain shutdown & hook execution order
* 🩹 Fix: Possible Data Race on shutdownHookCalled Variable
* 🩹 Fix: Remove the default Case
* 🩹 Fix: Import sync/atomic
* 🩹 Fix: golangci-lint problem
* 🎨 Style: add block in api.md
* 🩹 Fix: go mod tidy
* feat: Optimize ShutdownWithContext method in app.go
- Reorder mutex lock acquisition to the start of the function
- Early return if server is not running
- Use defer for executing shutdown hooks
- Simplify nil check for hooks
- Remove TODO comment
This commit improves the readability, robustness, and execution order
of the shutdown process. It ensures consistent state throughout the
shutdown and guarantees hook execution even in error cases.
* feat: Enhance ShutdownWithContext test for improved reliability
- Add shutdown hook verification
- Implement better synchronization with channels
- Improve error handling and assertions
- Adjust timeouts for more consistent results
- Add server state check after shutdown attempt
- Include comments explaining expected behavior
This commit improves the comprehensiveness and reliability of the
ShutdownWithContext test, ensuring proper verification of shutdown
hooks, timeout behavior, and server state during long-running requests.
* 📚 Doc: update the docs to explain shutdown & hook execution order
* 🩹 Fix: Possible Data Race on shutdownHookCalled Variable
* 🩹 Fix: Remove the default Case
* 🩹 Fix: Import sync/atomic
* 🩹 Fix: golangci-lint problem
* 🎨 Style: add block in api.md
* 🩹 Fix: go mod tidy
* ♻️ Refactor: replaced OnShutdown by OnPreShutdown and OnPostShutdown
* ♻️ Refactor: streamline post-shutdown hook execution in graceful shutdown process
* 🚨 Test: add test for gracefulShutdown
* 🔥 Feature: Using executeOnPreShutdownHooks and executeOnPostShutdownHooks Instead of OnShutdownSuccess and OnShutdownError
* 🩹 Fix: deal Listener err
* 🩹 Fix: go lint error
* 🩹 Fix: reduced memory alignment
* 🩹 Fix: reduced memory alignment
* 🩹 Fix: context should be created inside the concatenation.
* 📚 Doc: update what_new.md and hooks.md
* ♻️ Refactor: use blocking channel instead of time.Sleep
* 🩹 Fix: Improve synchronization in error propagation test.
* 🩹 Fix: Replace sleep with proper synchronization.
* 🩹 Fix: Server but not shut down properly
* 🩹 Fix: Using channels to synchronize and pass results
* 🩹 Fix: timeout with long running request
* 📚 Doc: remove OnShutdownError and OnShutdownSuccess from fiber.md
* Update hooks.md
* 🚨 Test: Add graceful shutdown timeout error test case
* 📝 Doc: Restructure hooks documentation for OnPreShutdown and OnPostShutdown
* 📝 Doc: Remove extra whitespace in hooks documentation
---------
Co-authored-by: yingjie.huang <yingjie.huang@fosunhn.net>
Co-authored-by: Juan Calderon-Perez <835733+gaby@users.noreply.github.com>
Update intro.md Static Files section
In v3 the apps Static method has been removed and its functionality has been moved to the static middleware.
The given code example has been updated accordingly.