Documentation ¶
Index ¶
Examples ¶
Constants ¶
View Source
const ( ValueTypeString = iota ValueTypeList ValueTypeKV )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Template ¶
type Template struct {
// contains filtered or unexported fields
}
Template represents a URI Template.
func New ¶
New parses and constructs a new Template instance based on the template. New returns an error if the template cannot be recognized.
func (*Template) Expand ¶
Expand returns a URI reference corresponding to the template expanded using the passed variables.
Example ¶
tmpl := MustNew("https://example.com/dictionary/{term:1}/{term}") vars := Values{} vars.Set("term", String("cat")) ret, err := tmpl.Expand(vars) if err != nil { fmt.Println(err) return } fmt.Println(ret)
Output: https://example.com/dictionary/c/cat
func (*Template) Match ¶
Example ¶
tmpl := MustNew("https://example.com/dictionary/{term:1}/{term}") match := tmpl.Match("https://example.com/dictionary/c/cat") if match == nil { fmt.Println("not matched") return } fmt.Printf("term:1 is %q\n", match.Get("term:1").String()) fmt.Printf("term is %q\n", match.Get("term").String())
Output: term:1 is "c" term is "cat"
func (*Template) Regexp ¶
Regexp converts the template to regexp and returns compiled *regexp.Regexp.
Example ¶
tmpl := MustNew("https://example.com/dictionary/{term:1}/{term}") re := tmpl.Regexp() fmt.Println(re.MatchString("https://example.com/dictionary/c/cat")) fmt.Println(re.MatchString("https://example.com/dictionary/c/a/cat"))
Output: true false
type Value ¶
Click to show internal directories.
Click to hide internal directories.