router

package
v0.0.0-...-c97fb91 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2020 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithParams

func WithParams(ctx context.Context, params Params) context.Context

WithParams can be used to annotate the context of a request with route params.

Types

type Mux

type Mux struct {
	DefaultHandler http.Handler
	Routes         []Route
}

Mux is a set of routes.

NOTE(henvic): This could be a tree router too, but this should be good and simple enough.

func (*Mux) ServeHTTP

func (m *Mux) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP handles request using the mux router. URL paths are normalized by stripping trailing slash. If a match is not found, it uses the m.DefaultHandler or http.NotFound if a default handler is not set.

func (*Mux) Validate

func (m *Mux) Validate()

Validate router mux entries.

type Params

type Params map[string]string

Params for routing URL paths.

func ReadParams

func ReadParams(ctx context.Context) Params

ReadParams from context.

func (Params) Get

func (p Params) Get(field string) string

Get param field value.

type Route

type Route struct {
	Pattern string
	Methods []string
	Handler http.Handler
	// contains filtered or unexported fields
}

Route for the HTTP server. Pattern uses a :field format. Pattern example: /products/:product_id/details Method cannot be empty.

func (*Route) Match

func (r *Route) Match(method, path string) (Params, bool)

Match route.

func (*Route) MatchPath

func (r *Route) MatchPath(path string) (Params, bool)

MatchPath with route.

Jump to

Keyboard shortcuts

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