routes

package
v1.0.8 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2023 License: GPL-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RT_PATH_VAR_PREFIX = "<<"
	RT_PATH_VAR_SUFFIX = ">>"
	RT_PATH_VAR_DELIM  = ":"
)

Router regex delimiters

View Source
const (
	NameInt    = "int"
	NameString = "string"
	NameSlug   = "slug"
	NameUUID   = "uuid"
	NameAny    = "any"
	NameHex    = "hex"
)

Router regex types.

View Source
const (
	// Match any character
	RT_PATH_REGEX_ANY = ".+"
	// Match any number
	RT_PATH_REGEX_NUM = "[0-9]+"
	// Match any string
	RT_PATH_REGEX_STR = "[a-zA-Z]+"
	// Match any hex number
	RT_PATH_REGEX_HEX = "[0-9a-fA-F]+"
	// Match any UUID
	RT_PATH_REGEX_UUID = "[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}"
	// Match any alphanumeric string
	RT_PATH_REGEX_ALPHANUMERIC = "[0-9a-zA-Z_-]+"
)

Router regex patterns

Variables

This section is empty.

Functions

This section is empty.

Types

type Route

type Route struct {
	Name          string
	Internal_name string
	Path          string

	// Function to be called when the route is called.
	Callable func(v vars.Vars, u *url.URL)

	// Function to be called when the route is left.
	OnLeave func(v vars.Vars, u *url.URL)

	// URL used to match the route.
	RegexUrl string
	// Wether to skip the trailing slash.
	SkipTrailingSlash bool
	// Children of the route.
	Children []*Route
}

Routes to be registered in the router

func (*Route) GetRoute

func (r *Route) GetRoute(name string) *Route

func (*Route) Match

func (r *Route) Match(path string) (bool, *Route, vars.Vars)

If the path matches the route, return true and the named capture groups If capture group is not named, returns $1, $2, etc.

func (*Route) Register

func (r *Route) Register(name, path string, callable func(v vars.Vars, u *url.URL)) *Route

Register a new route as a child of this route If the path does not start with a slash, and r.Path does not end in one then a slash is added to the path

-> Route{Path: "/api", Children: []*Route{Path: "posts/"}}

Will result in the path "/api/posts"

func (*Route) String

func (r *Route) String() string

func (*Route) StringIndent

func (r *Route) StringIndent(sb *strings.Builder, level int)

func (*Route) URL

func (r *Route) URL(args ...any) string

Format the url based on the arguments given. Panics if route accepts more arguments than are given.

Jump to

Keyboard shortcuts

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