path_template

package
v1.0.12 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 18, 2024 License: Apache-2.0 Imports: 5 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ResolveRelative

func ResolveRelative(basestr, relstr string) string

ResolveRelative resolves relatives such as "http://www.golang.org/" and "topics/myproject/mytopic" into a single string, such as "http://www.golang.org/topics/myproject/mytopic". It strips all parent references (e.g. ../..) as well as anything after the host (e.g. /bar/gaz gets stripped out of foo.com/bar/gaz).

ResolveRelative panics if either basestr or relstr is not able to be parsed.

Types

type ParseError

type ParseError struct {
	Pos      int
	Template string
	Message  string
}

func (ParseError) Error

func (pe ParseError) Error() string

type PathTemplate

type PathTemplate struct {
	// contains filtered or unexported fields
}

PathTemplate manages the template to build and match with paths used by API services. It holds a template and variable names in it, and it can extract matched patterns from a path string or build a path string from a binding.

See http.proto in github.com/googleapis/googleapis/ for the details of the template syntax.

func MustCompilePathTemplate

func MustCompilePathTemplate(template string) *PathTemplate

MustCompilePathTemplate is like NewPathTemplate but panics if the expression cannot be parsed. It simplifies safe initialization of global variables holding compiled regular expressions.

func NewPathTemplate

func NewPathTemplate(template string) (*PathTemplate, error)

NewPathTemplate parses a path template, and returns a PathTemplate instance if successful.

func (*PathTemplate) Match

func (pt *PathTemplate) Match(path string) (map[string]string, error)

Match attempts to match the given path with the template, and returns the mapping of the variable name to the matched pattern string.

func (*PathTemplate) Render

func (pt *PathTemplate) Render(binding map[string]string) (string, error)

Render creates a path string from its template and the binding from the variable name to the value.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL