feat(router)!: add UseOuter middleware layer and update Predicate signature#458
Open
fluffur wants to merge 5 commits into
Open
feat(router)!: add UseOuter middleware layer and update Predicate signature#458fluffur wants to merge 5 commits into
fluffur wants to merge 5 commits into
Conversation
Predicates can now read database configurations, flags, and other data pre-loaded by the new UseOuter middleware layer. BREAKING CHANGE: The `Predicate` type signature changed from `func(u *Update) bool` to `func(c *Context) bool`. To fix this, update your custom predicate functions to accept `*Context` and read the update via `c.Update` if needed.
…ature Added a dedicated section for "Outer Middleware" in the README to explain the middleware lifecycle and pipeline execution order. BREAKING CHANGE: Updated examples and documentation to reflect that `Predicate` now accepts `*Context` instead of `*Update`.
948d681 to
c7f4425
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #458 +/- ##
==========================================
- Coverage 78.78% 78.73% -0.05%
==========================================
Files 118 118
Lines 8316 8325 +9
==========================================
+ Hits 6552 6555 +3
- Misses 1237 1242 +5
- Partials 527 528 +1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
bfb6600 to
76e2023
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request introduces a new global middleware layer called
UseOuterand updates thePredicatesignature to be context-aware.Key Changes
bot.UseOuter(), which allows registering global middlewares that run before route matching. This is useful for firewalls, blacklists, or pre-loading database configurations.Predicatesignature so it now accepts*botapi.Contextinstead of*botapi.Update. This allows route guards to read data injected into the context by the newUseOutermiddlewares (for example, custom command prefixes).Execution Order
An incoming update now passes through the bot in this sequence:
bot.UseOuter()->bot.Predicate()matching ->bot.Use()->bot.HandlerBREAKING CHANGES and Migration Guide
The Predicate type signature has changed from
func(u *Update) booltofunc(c *Context) bool. Existing custom predicates will cause compilation errors and must be updated.How to migrate:
Change the function argument from
*botapi.Updateto*botapi.Context. If your code requires raw update fields, access them throughc.Updateor use context helper methods.Documentation and Examples
README.mdexplaining the new pipeline lifecycle.examples/middleware/main.goto demonstrate how data moves fromUseOuterto predicates and handlers.