### Install uritemplate package Source: https://pkg.go.dev/github.com/yosida95/uritemplate/v3 Use the go get command to add the package to your project dependencies. ```sh $ go get -u github.com/yosida95/uritemplate/v3 ``` -------------------------------- ### Create Value Instances Source: https://pkg.go.dev/github.com/yosida95/uritemplate/v3 Constructors for different types of template values. ```go func KV(kv ...string) Value ``` ```go func List(v ...string) Value ``` ```go func String(v string) Value ``` -------------------------------- ### Create New Template Source: https://pkg.go.dev/github.com/yosida95/uritemplate/v3 Functions to instantiate a new Template, with MustNew panicking on failure. ```go func MustNew(template string) *Template ``` ```go func New(template string) (*Template, error) ``` -------------------------------- ### Expand Template Source: https://pkg.go.dev/github.com/yosida95/uritemplate/v3 Expands a template into a URI string using provided variables. ```go func (t *Template) Expand(vars Values) (string, error) ``` ```text Output: https://example.com/dictionary/c/cat ``` -------------------------------- ### New(template string) (*Template, error) Source: https://pkg.go.dev/github.com/yosida95/uritemplate/v3 Parses and constructs a new Template instance from a string. Returns an error if the template format is invalid. ```APIDOC ### func New #### Description Parses and constructs a new Template instance based on the provided template string. #### Signature `func New(template string) (*Template, error)` #### Parameters - **template** (string) - Required - The URI template string to parse. #### Returns - **(*Template)** - A pointer to the initialized Template instance. - **(error)** - An error if the template cannot be recognized. ``` -------------------------------- ### Match Expansion Source: https://pkg.go.dev/github.com/yosida95/uritemplate/v3 Matches an expanded URI string against a template to extract variables. ```go func (tmpl *Template) Match(expansion string) Values ``` ```text Output: term:1 is "c" term is "cat" ``` -------------------------------- ### Define Equals Function Source: https://pkg.go.dev/github.com/yosida95/uritemplate/v3 Reports whether two URI Templates are equivalent based on provided flags. ```go func Equals(t1 *Template, t2 *Template, flags CompareFlags) bool ``` -------------------------------- ### Access Template Metadata Source: https://pkg.go.dev/github.com/yosida95/uritemplate/v3 Methods to retrieve the raw template string, compiled regex, or variable names. ```go func (t *Template) Raw() string ``` ```go func (t *Template) Regexp() *regexp.Regexp ``` ```text Output: true false ``` ```go func (t *Template) Varnames() []string ``` -------------------------------- ### Define Template Struct Source: https://pkg.go.dev/github.com/yosida95/uritemplate/v3 Represents a parsed URI Template. ```go type Template struct { // contains filtered or unexported fields } ``` -------------------------------- ### Template.Match(expansion string) Values Source: https://pkg.go.dev/github.com/yosida95/uritemplate/v3 Matches an expanded URI string against the template to extract variable values. ```APIDOC ### func (*Template) Match #### Description Matches an expansion string against the template and returns the extracted variable values. #### Signature `func (tmpl *Template) Match(expansion string) Values` #### Parameters - **expansion** (string) - Required - The expanded URI string to match against the template. #### Returns - **(Values)** - A map of extracted variable names and their values. ``` -------------------------------- ### Template.Expand(vars Values) (string, error) Source: https://pkg.go.dev/github.com/yosida95/uritemplate/v3 Expands a URI template using the provided variable map. ```APIDOC ### func (*Template) Expand #### Description Returns a URI reference corresponding to the template expanded using the passed variables. #### Signature `func (t *Template) Expand(vars Values) (string, error)` #### Parameters - **vars** (Values) - Required - A map of variable names to their corresponding values. #### Returns - **(string)** - The expanded URI string. - **(error)** - An error if expansion fails. ``` -------------------------------- ### Define ValueType Source: https://pkg.go.dev/github.com/yosida95/uritemplate/v3 Type definition and string representation for Value types. ```go type ValueType uint8 ``` ```go func (vt ValueType) String() string ``` -------------------------------- ### Value Accessor Methods Source: https://pkg.go.dev/github.com/yosida95/uritemplate/v3 Methods to retrieve or validate the contents of a Value. ```go func (v Value) KV() []string ``` ```go func (v Value) List() []string ``` ```go func (v Value) String() string ``` ```go func (v Value) Valid() bool ``` -------------------------------- ### Define Value Struct Source: https://pkg.go.dev/github.com/yosida95/uritemplate/v3 Represents a value used in template expansion. ```go type Value struct { T ValueType V []string } ``` -------------------------------- ### Define CompareFlags Type Source: https://pkg.go.dev/github.com/yosida95/uritemplate/v3 Flags used for comparing URI Templates. ```go type CompareFlags uint8 ``` ```go const ( CompareVarname CompareFlags = 1 << iota ) ``` -------------------------------- ### Define Values Map Source: https://pkg.go.dev/github.com/yosida95/uritemplate/v3 A collection of values mapped by variable name. ```go type Values map[string]Value ``` ```go func (v Values) Get(name string) Value ``` ```go func (v Values) Set(name string, value Value) ``` -------------------------------- ### Define ValueType Constants Source: https://pkg.go.dev/github.com/yosida95/uritemplate/v3 Constants representing the type of data held by a Value. ```go const ( ValueTypeString = iota ValueTypeList ValueTypeKV ) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.