route

package
v2.12.3 Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2015 License: MIT Imports: 2 Imported by: 8

Documentation

Overview

Package route provides slim representation of routes that is used by go-on/router.Router and may be used by client side libraries such as gopherjs.

A route intentionally has no handler. That is left to be defined/assigned by the server side library - that is go-on/router. Therefor some properties of Route that must not be changed by hand are exported to allow go-on/router to do its work.

Index

Constants

This section is empty.

Variables

View Source
var PARAM_PREFIX = []byte(":")[0]

Functions

func Mount

func Mount(mountPoint string, routes ...*Route)

Mount mounts the given routes beneath the given mountPoint It should be used in libraries that are used by a client or shared between client and server

func Options

func Options(r *Route) []string

Options returns an array that may be used by handlers for the OPTIONS http method

Types

type ErrDoubleMounted

type ErrDoubleMounted struct {
	Path  string
	Route *Route
}

ErrDoubleMounted is raised if the route already has been mounted.

func (*ErrDoubleMounted) Error

func (e *ErrDoubleMounted) Error() string

type ErrMissingParam

type ErrMissingParam struct {
	Param       string
	MountedPath string
}

ErrMissingParam is raised if a route URL parameter is missing.

func (ErrMissingParam) Error

func (e ErrMissingParam) Error() string

type ErrPairParams

type ErrPairParams struct{}

ErrPairParams is raised if a variadic parameter group has no pairs.

func (ErrPairParams) Error

func (ErrPairParams) Error() string

type ErrRouteIsNil

type ErrRouteIsNil struct{}

ErrRouteIsNil is raised if a route is not yet defined.

func (ErrRouteIsNil) Error

func (e ErrRouteIsNil) Error() string

type ErrUnknownMethod

type ErrUnknownMethod struct {
	method.Method
}

ErrUnknownMethod is raised if the given http method is not known.

func (ErrUnknownMethod) Error

func (e ErrUnknownMethod) Error() string

type Route

type Route struct {

	// Id will be set by the go-on/router.Router, don't touch it!
	// An internal attribute but exported because it is cross-package
	Id string

	// Methods will be read by the go-on/router.Router, don't touch it!
	// An internal attribute but exported because it is cross-package
	Methods map[method.Method]struct{}

	// DefinitionPath will be read by the go-on/router.Router, don't touch it!
	// An internal attribute but exported because it is cross-package
	DefinitionPath string

	// Router will be set by either Mount or go-on/router.Router, don't touch it!
	// An internal attribute but exported because it is cross-package
	Router interface {
		// MountPath returns the path where the router is mounted
		MountPath() string
	}
}

Don't directly change the properties of Route. Instead use only the methods. These properties only are exported to be used by Router

func New

func New(path string, method1 method.Method, furtherMethods ...method.Method) *Route

New creates a new route for the given path and methods. The methods for the route must not be changed after the call of New

func (*Route) HasMethod

func (r *Route) HasMethod(m method.Method) (has bool)

HasMethod checks if the route has the given method.

func (*Route) HasParams

func (r *Route) HasParams() bool

HasParams checks if the path of the route has placeholders for params

func (*Route) MountedPath

func (r *Route) MountedPath() string

MountedPath returns the path of the mounted route

func (*Route) MustURL

func (r *Route) MustURL(params ...string) string

MustURL is like URL but panics on errors

func (*Route) MustURLMap

func (r *Route) MustURLMap(params map[string]string) string

MustURLMap is like URLMap but panics on errors

func (*Route) URL

func (r *Route) URL(params ...string) (string, error)

URL returns the url of the mounted route for the given params (key/value pairs)

func (*Route) URLMap

func (r *Route) URLMap(params map[string]string) (string, error)

URL returns the url of the mounted route for the given params (map)

Directories

Path Synopsis
example
Package routehtml provides shortcuts to deal with route and go-on/lib/html
Package routehtml provides shortcuts to deal with route and go-on/lib/html

Jump to

Keyboard shortcuts

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