Skip to content

Latest commit

 

History

History
60 lines (41 loc) · 1.46 KB

File metadata and controls

60 lines (41 loc) · 1.46 KB

urlpath

Go Reference License Build

urlpath provides a way to parse URL path elements using a schema

For users of gorilla/mux.

Getting Started

The urlpath package can be added to a project by running:

go get cattlecloud.net/go/urlpath@latest
import "cattlecloud.net/go/urlpath"

Examples

mux definition

Make use of gorilla's path variables.

router.Handle("/v1/{category}/{name}", newHandler())
parsing schema

Create a Schema and call Parse to extract the path variables.

var (
  category int
  name     string
)

urlpath.MustParse(request, urlpath.Schema {
  "category": urlpath.Int(&category),
  "name":     urlpath.String(&name),
})

A error version also exists.

err := urlpath.Parse(request, urlpath.Schema {
  "category": urlpath.Int(&category),
  "name":     urlpath.String(&name),
})

License

The cattlecloud.net/go/urlpath module is open source under the BSD license.