You can check how violetear handles dynamic + catchall (wildcard) templates, this is just to complement, for example:
uuid := `[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}` router.AddRegex(":uuid") router.HandleFunc("/test/:uuid/:uuid", handleUUID, "GET,HEAD")
In this case, the request may have 2 different UUIDS
For a dynamic / wildcard, this can apply:
http://api.violetear.org/command/ping/127.0.0.1 \______/\___/\________/ | | | static | dynamic
A regular expression can be used to match IP:
router.AddRegex(":ip", `^(?:[0-9]{1,3}\.){3}[0-9]{1,3}$`) router.HandleFunc("/command/ping/:ip", ipHandler, "GET")
Or just just catch everything that only the GET and HEAD methods allow:
router.HandleFunc("/command/ping/*", anyHandler, "GET, HEAD")
Additional examples can be found here: https://violetear.org/post/how-it-works/
nbari Sep 10 '17 at 11:47 on 2017-09-10 11:47
source share