routevar

package
v0.0.0-...-cf05d5b Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2015 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package routevar contains mux route variable declarations (e.g., `{Repo:<regexp>}`) and PostMatchFuncs/BuildVarsFuncs.

Index

Constants

This section is empty.

Variables

View Source
var (
	// Repo captures RepoSpec strings in URL routes.
	Repo = `{Repo:` + NamedToNonCapturingGroups(spec.RepoPattern) + `}`

	// RepoRev captures RepoRevSpec strings in URL routes.
	RepoRev = Repo + `{ResolvedRev:(?:@` + NamedToNonCapturingGroups(spec.ResolvedRevPattern) + `)?}`
)
View Source
var (
	// User captures UserSpec strings in URL routes.
	User = `{User:` + NamedToNonCapturingGroups(spec.UserPattern) + `}`

	// Person captures PersonSpec strings in URL routes.
	Person = `{Person:` + NamedToNonCapturingGroups(spec.UserPattern) + `}`
)
View Source
var Def = `.{UnitType}/{rawUnit:.*}.def{Path:(?:(?:/(?:[^/.][^/]*/)*(?:[^/.][^/]*))|)}`

Def captures def paths in URL routes.

We want the def routes to match the 2 following forms:

  1. /.MyUnitType/.def/MyDef (i.e., Unit == ".")
  2. /.MyUnitType/MyUnitPath1/.def/MyDef (i.e., Unit == "MyUnitPath1")

To achieve this, we use a non-picky regexp for rawUnit and then sort it out in the FixDefUnitVars PostMatchFunc.

View Source
var TreeEntryPath = `{Path:(?:/.*)*}`

TreeEntryPath captures tree entry paths in URL routes.

Functions

func FixDefUnitVars

func FixDefUnitVars(req *http.Request, match *mux.RouteMatch, r *mux.Route)

FixDefUnitVars is a mux.PostMatchFunc that cleans up the dummy rawUnit route variable matched by Def. See the docs for Def for more information.

func FixRepoRevVars

func FixRepoRevVars(req *http.Request, match *mux.RouteMatch, r *mux.Route)

FixRepoRevVars is a mux.PostMatchFunc that cleans and normalizes the route vars pertaining to a RepoRev.

func FixResolvedRevVars

func FixResolvedRevVars(req *http.Request, match *mux.RouteMatch, r *mux.Route)

FixResolvedRevVars is a mux.PostMatchFunc that cleans and normalizes the route vars pertaining to a ResolvedRev (Rev and CommitID).

func FixTreeEntryVars

func FixTreeEntryVars(req *http.Request, match *mux.RouteMatch, r *mux.Route)

FixTreeEntryVars is a mux.PostMatchFunc that cleans and normalizes the path to a tree entry.

func NamedToNonCapturingGroups

func NamedToNonCapturingGroups(pat string) string

NamedToNonCapturingGroups converts named capturing groups `(?P<myname>...)` to non-capturing groups `(?:...)` for use in mux route declarations (which assume that the route patterns do not have any capturing groups).

func PrepareDefRouteVars

func PrepareDefRouteVars(vars map[string]string) map[string]string

PrepareDefRouteVars is a mux.BuildVarsFunc that converts from a "Unit" route variable to the dummy "rawUnit" route variable that actually appears in the route regexp pattern.

func PrepareRepoRevRouteVars

func PrepareRepoRevRouteVars(vars map[string]string) map[string]string

PrepareRepoRevRouteVars is a mux.BuildVarsFunc that converts from a RepoRevSpec's route vars to components used to generate routes.

func PrepareResolvedRevRouteVars

func PrepareResolvedRevRouteVars(vars map[string]string) map[string]string

PrepareResolvedRevRouteVars is a mux.BuildVarsFunc that converts from a ResolvedRev's component route vars (Rev and CommitID) to a single ResolvedRev var.

func PrepareTreeEntryRouteVars

func PrepareTreeEntryRouteVars(vars map[string]string) map[string]string

PrepareTreeEntryRouteVars is a mux.BuildVarsFunc that converts from a cleaned and normalized Path to a Path that we use to generate tree entry URLs.

Types

This section is empty.

Jump to

Keyboard shortcuts

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