Using a named subpath in the URL
Author: verdelCreated Mar 10, 2025Updated Aug 25, 2026
Is it possible to use a named subPath in the URL? Suppose we have the following URL pattern:
r.Get("/hook/{name:.*}/snapshots.{format:(json|yaml|text)}", func(w http.ResponseWriter, r *http.Request) {
hookName := chi.URLParam(r, "name")
})However, if the URL looks like /hook/100-test/test.sh/snapshots.text, it will not be processed because the pattern {name:.*} matches 100-test but not 100-test/test.sh.
This is also mentioned in the documentation:
The regular expression syntax is Go’s normal regexp RE2 syntax, except that regular expressions including { or } are not supported, and / will never be matched.We don’t know how many levels of nesting will be after /hook and before /snapshots.{format:(json|yaml|text)}. Essentially, the URL structure mirrors the file system structure.
Source: go-chi/chi