urlpath
provides a way to parse URL path elements using a schema
For users of gorilla/mux.
The urlpath
package can be added to a project by running:
go get cattlecloud.net/go/urlpath@latest
import "cattlecloud.net/go/urlpath"
Make use of gorilla's path variables.
router.Handle("/v1/{category}/{name}, newHandler())
Create a Schema
and call Parse
to extract the path variables.
var (
category int
name string
)
err := urlpath.Parse(request, urlpath.Schema {
"category": urlpath.Int(&category),
"name": urlpath.String(&name),
})
The cattlecloud.net/go/urlpath
module is open source under the BSD license.