gorilla / mux

Package gorilla/mux is a powerful HTTP router and URL matcher for building Go web servers with 🦍
https://gorilla.github.io
BSD 3-Clause "New" or "Revised" License
20.93k stars 1.85k forks source link

pattern aliases #675

Open HiveTraum opened 2 years ago

HiveTraum commented 2 years ago

✋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}")
  1. New method RegisterPattern on Route struct
  2. New method RegisterPattern on Router struct
amustaque97 commented 2 years ago

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.

HiveTraum commented 2 years ago

@amustaque97 Done 👍

amustaque97 commented 2 years ago

@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?

HiveTraum commented 1 year ago

Yes, it's ready to merge