way

package module
v0.0.0-...-9578b11 Latest Latest
Warning

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

Go to latest
Published: Jun 27, 2020 License: Apache-2.0 Imports: 3 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidChars = errors.New("Invalid characters")

ErrInvalidChars is returned when invalid characters are used in the route

View Source
var ErrMiddleSuffix = errors.New("Suffix parameters can only happen at the end of the path")

ErrMiddleSuffix is returned when the provided path contains a suffix not located at the end

View Source
var ErrMissingParam = errors.New("Missing parameter")

ErrMissingParam is returned when there is a missing parameter

View Source
var ErrNotFound = errors.New("Requested route not found")

ErrNotFound is returned when the requested route could not be found

Functions

This section is empty.

Types

type Params

type Params = map[string][]string

Params hold information about provided or matched URL parameters

func Merge

func Merge(params ...Params) Params

Merge builds new parameters after merging provided ones

type Route

type Route = []string

Route contains the matched route

func Clone

func Clone(route Route) Route

Clone returns a copy of the provided route

type RouteMap

type RouteMap = map[string]Route

RouteMap holds a list of route mappings

type Router

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

Router holds the list of routings and mappings

func BuildRouter

func BuildRouter(maps ...RouteMap) Router

BuildRouter builds a new router instance and adds the provided routes to it, panicking if there's an error adding the routes

func NewRouter

func NewRouter() Router

NewRouter builds a new router instance

func (Router) Add

func (r Router) Add(path string, route ...string) error

Add adds a route to the router

func (Router) AddAll

func (r Router) AddAll(m RouteMap) error

AddAll adds all provided routes to the router

func (Router) GetRoute

func (r Router) GetRoute(urlToMatch *url.URL) (Params, Route, error)

GetRoute gets the route and params for the given URL

func (Router) GetURL

func (r Router) GetURL(originalParams Params, route ...string) (string, error)

GetURL gets the URL from the given route and parameters

func (Router) MustGetRoute

func (r Router) MustGetRoute(urlToMatch *url.URL) (Params, Route)

MustGetRoute gets the URL from the given route and parameters and panics if there's an error

func (Router) MustGetURL

func (r Router) MustGetURL(originalParams Params, route ...string) string

MustGetURL gets the URL from the given route and parameters and panics if there's an error

Jump to

Keyboard shortcuts

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