pathmap

package
v0.0.57 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2021 License: Apache-2.0, NCSA Imports: 5 Imported by: 1

Documentation

Overview

Package pathmap provides utilities for matching and generating paths based on a pattern string.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Mapper

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

Mapper provides path parsing and generating with named segments See NewMapper for details on construction

func NewMapper

func NewMapper(pat string) (*Mapper, error)

NewMapper produces a Mapper object from a pattern string. Patterns strings are paths that have named segments that are extracted during parsing and populated during generation. Example:

		m := NewMapper("/dir/:segment/home/:rest*")
 	s, err := m.Parse("/dir/foo/home/hello/world")	// {"segment": "foo", "rest": "hello/world"}, nil
		p := m.Generate(s) 								// /dir/foo/home/hello/world

func (Mapper) Generate

func (m Mapper) Generate(vars map[string]string) (string, error)

Generate produces a path from a map of segment values. All required values must be present

func (Mapper) Parse

func (m Mapper) Parse(path string) (map[string]string, error)

Parse extracts named segments from the path provided All segments must appear in the path

Jump to

Keyboard shortcuts

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