routing

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2022 License: BSD-3-Clause Imports: 9 Imported by: 0

Documentation

Overview

Package routing provides the name resolving utility for the fasthttp.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Middleware

type Middleware = func(next Router) Router

Middleware is a wrapping function that filters the request.

type NestedRouter

type NestedRouter func() Router

NestedRouter is a generator function that returns the Router handler.

type Router

type Router = fasthttp.RequestHandler

Router is an alias type of the fasthttp.RequestHandler.

func ApplyMiddlware

func ApplyMiddlware(source Router, middlewares ...Middleware) (handler Router)

ApplyMiddlware is a function that applies the given middleware for the handler.

func JustCode

func JustCode(statusHandler eighty.HandledError, middlewares ...Middleware) (handler Router)

JustCode is a simple handler function that just only returns the http status code.

type RouterContext

type RouterContext interface {
	// UrlResolver returns a UrlResolver.
	UrlResolver() UrlResolver

	// UrlPrefix returns the URL prefix that is added across the entire routing group.
	UrlPrefix() string

	// BuildRouter returns a RouterRegistry for register grouped routing.
	BuildRouter(errHandleMiddleware Middleware) RouterRegistry
	// contains filtered or unexported methods
}

RouterContext is a fasthttp request url routing context.

func NewRouterContext

func NewRouterContext(
	urlPrefix string,
	reverseRouter UrlFor,
) (ctx RouterContext)

NewRouterContext returns a RouterContext.

type RouterRegistry

type RouterRegistry interface {
	RouterContext
	// Name returns the current group name.
	Name() string
	// ToContext returns the current group name.
	ToContext() RouterContext
	// Register is a registration method for http request.
	Register(
		name string, path string, params []string,
		handler Router,
		middlewares []Middleware,
		methods ...string,
	)
	// RegisterNested is a registration method for http request with a router generator.
	RegisterNested(
		name string, path string, params []string,
		routerGenerator NestedRouter,
		middlewares []Middleware,
		methods ...string,
	)
	// Wrap returns a child RouterRegistry with specified name and path.
	Wrap(name string, path string, middlewares ...Middleware) RouterRegistry
	// Handler is a handler method that process incoming requests.
	// It implements the Router interface.
	Handler(ctx *fasthttp.RequestCtx)
}

RouterRegistry is a fasthttp request url routing builder.

type UrlFor

type UrlFor interface {
	UrlResolver
	// Add registers name, parameter, and URL for UrlResolver.
	// If a duplicate name exists, an error is returned instead of registering.
	Add(urlName, urlAddr string, params ...string) (string, error)
	// MustAdd registers name, parameter, and URL for UrlResolver.
	// If a duplicate name exists, it panics.
	MustAdd(urlName, urlAddr string, params ...string) string
	// AddGr registers name, parameter, and URL for UrlResolver with nested group infos.
	// If a duplicate name exists, an error is returned instead of registering.
	AddGr(urlName, urlAddr string, groupNames, groupAddrs []string, params ...string) (string, error)
	// MustAddGr registers name, parameter, and URL for UrlResolver with nested group infos.
	// If a duplicate name exists, it panics.
	MustAddGr(urlName, urlAddr string, groupNames, groupAddrs []string, params ...string) string
	// Clear clears all registered reverse-routing infos.
	Clear()
	// String returns summarized info of registered reverse-routing infos.
	String() string
	// ToResolver returns a UrlResolver.
	ToResolver() UrlResolver
}

UrlFor is a reverse-routing utility that stores the handler information.

func NewUrlFor

func NewUrlFor() UrlFor

NewUrlFor returns a UrlFor.

type UrlResolver

type UrlResolver interface {
	// Get is a resolver function that takes a name and parameters and returns a URL. If the URL is not found, it panics.
	Get(urlName string, params ...string) string
	// Reverse is a resolver function that takes a name and parameters and returns a URL.
	Reverse(urlName string, params ...string) (string, error)
	// ReverseWithParams is a resolver function that takes a name and parameters and returns a URL.
	ReverseWithParams(urlName string, params []string) (string, error)
	// MustReverse is a resolver function that takes a name and parameters and returns a URL. If the URL is not found, it panics.
	MustReverse(urlName string, params ...string) string
	// MustReverseWithParams is a resolver function that takes a name and parameters and returns a URL. If the URL is not found, it panics.
	MustReverseWithParams(urlName string, params []string) string
}

UrlResolver is a URL resolver utility that stores the handler information registered by UrlFor.

Jump to

Keyboard shortcuts

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