mux

package
v0.0.69 Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2023 License: MIT Imports: 4 Imported by: 5

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MatchedRoute

type MatchedRoute struct {
	Pattern  string
	PathVars map[string]string
}

MatchedRoute is provided in the context to Gemini handlers that use the router.

func GetMatchedRoute

func GetMatchedRoute(ctx context.Context) (mr MatchedRoute, ok bool)

GetMatchedRoute returns the route that was matched by the router, along with any path variables extracted from the URL.

type Mux

type Mux struct {
	RouteHandlers   []*RouteHandler
	NotFoundHandler gemini.Handler
}

Mux routes Gemini requests to the appropriate handler.

func NewMux

func NewMux() *Mux

NewMux creates a new Mux for routing requests.

func (*Mux) AddRoute

func (m *Mux) AddRoute(pattern string, handler gemini.Handler)

AddRoute to the mux.

func (*Mux) ServeGemini

func (m *Mux) ServeGemini(w gemini.ResponseWriter, r *gemini.Request)

type Route

type Route struct {
	Pattern  string
	Segments []*Segment
}

Route is an array of segments.

func NewRoute

func NewRoute(pattern string) *Route

NewRoute creates a route based on a pattern, e.g /users/{userid}.

func (Route) Match

func (r Route) Match(segments []string) (vars map[string]string, ok bool)

Match returns whether the route was matched, and extracts variables.

type RouteHandler

type RouteHandler struct {
	Route   *Route
	Handler gemini.Handler
}

RouteHandler is the Handler to use for a given Route.

type Segment

type Segment struct {
	Name       string
	IsVariable bool
	IsWildcard bool
}

Segment is a path segment, e.g. in /users/{userid}/ there are two segments, "users" and "{userid}". "{userid}" is a variable and will be captured.

func (*Segment) Match

func (ps *Segment) Match(s string) (name string, capture bool, wildcard bool, matches bool)

Match on the string path segment.

func (*Segment) String

func (ps *Segment) String() string

String pretty prints the segment, for debugging.

Jump to

Keyboard shortcuts

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