mux
mux copied to clipboard
pattern aliases
✋Reopened #598 because i noticed that the project came to life
This feature introduces ability to register aliases for some often used regular expressions.
For example path as this:
/{category:[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-4[a-fA-F0-9]{3}-[8|9|aA|bB][a-fA-F0-9]{3}-[a-fA-F0-9]{12}}/{product:[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-4[a-fA-F0-9]{3}-[8|9|aA|bB][a-fA-F0-9]{3}-[a-fA-F0-9]{12}}
can be transformed into this
/{category:uuid}/{product:uuid}
You need just use register it
router := NewRouter()
router.RegisterPattern("uuid", "[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-4[a-fA-F0-9]{3}-[8|9|aA|bB][a-fA-F0-9]{3}-[a-fA-F0-9]{12}")
router.Path("/{category:uuid}")
router.Path("/{product:uuid}")
router.Path("/{order:uuid}")
router.Path("/{user:uuid}")
- New method
RegisterPattern
onRoute
struct - New method
RegisterPattern
onRouter
struct
Thank you @HiveTraum for bringing this up again. I have added a couple of comments. I need some more time to review it completely. In the meantime, I Would love to hear from you.
@amustaque97 Done 👍
@elithrar , I reviewed the PR and changes looks good to me and ready to ship 🚀
I would request you to please take a final look at this and if all good. Can we merge it?
Yes, it's ready to merge