Extract path variables from URLs using URL templates.
Clone or download
Latest commit 45096e3 Nov 28, 2018
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
example Added multi-path wildcard. Jul 6, 2018
README.md First commit. Jun 22, 2018
pathmatcher.go Updated to handle strings. Nov 28, 2018
pathmatcher_test.go Updated to handle strings. Nov 28, 2018
route.go Don't accet partial matches. Jul 12, 2018
segment.go Added multi-path wildcard. Jul 6, 2018
segment_test.go Added multi-path wildcard. Jul 6, 2018

README.md

Extractor

Extracts path variables from URLs.

Example Usage

package main

import (
	"fmt"
	"net/http"

	"github.com/pathvars"
)

var matcher = pathvars.NewExtractor("/user/{userid}")

func main() {
	r, _ := http.NewRequest("GET", "/user/123", nil)
	values, ok := matcher.Extract(r.URL)
	fmt.Println("OK:", ok)
	fmt.Println("User ID:", values["userid"])
}

Example Output

$ go run main.go
OK: true
User ID: 123