inbuilt

package
v0.16.3 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2024 License: MIT Imports: 15 Imported by: 1

Documentation

Index

Constants

View Source
const AllErrors = status.Code(0)

AllErrors is used to be passed into Router.RouteError, indicating by that, that the handler must handle ALL errors (if concrete error's handler won't override it)

Variables

This section is empty.

Functions

This section is empty.

Types

type Catcher added in v0.13.0

type Catcher struct {
	Prefix  string
	Handler Handler
}

Catcher is used to catch requests, if no other handlers are available. This is used, for example, for static files distribution

type Handler added in v0.13.0

type Handler = types.Handler

type Middleware added in v0.13.0

type Middleware func(next Handler, request *http.Request) *http.Response

Middleware works like a chain of nested calls, next may be even directly handler. But if we are not a closing middleware, we will call next middleware that is simply a partial middleware with already provided next

type Mutator added in v0.15.0

type Mutator = types.Mutator

Mutator is kind of pre-middleware. It's being called at the moment, when a request arrives to the router, but before the routing will be done. So by that, the request may be mutated. For example, mutator may normalize requests' paths, log them, make invisible redirects, etc.

type Resource

type Resource struct {
	// contains filtered or unexported fields
}

Resource is just a wrapper of a group for some resource, allowing to attach multiple methods (and pointed-applied middlewares) to some single resource in a bit more convenient way than ordinary groups do. Actually, the only point of this object is to wrap a group to bypass an empty string into it as a path

func (Resource) Catch added in v0.10.5

func (r Resource) Catch(prefix string, handler Handler, mwares ...Middleware) Resource

Catch registers a catcher. A catcher is a handler, that is being called if requested path is not found, and it starts with a defined prefix

func (Resource) Connect

func (r Resource) Connect(handler Handler, mwares ...Middleware) Resource

Connect registers a handler for CONNECT-requests

func (Resource) Delete

func (r Resource) Delete(handler Handler, mwares ...Middleware) Resource

Delete registers a handler for DELETE-requests

func (Resource) Get

func (r Resource) Get(handler Handler, mwares ...Middleware) Resource

Get registers a handler for GET-requests

func (Resource) Head

func (r Resource) Head(handler Handler, mwares ...Middleware) Resource

Head registers a handler for HEAD-requests

func (Resource) Options

func (r Resource) Options(handler Handler, mwares ...Middleware) Resource

Options registers a handler for OPTIONS-requests

func (Resource) Patch

func (r Resource) Patch(handler Handler, mwares ...Middleware) Resource

Patch registers a handler for PATCH-requests

func (Resource) Post

func (r Resource) Post(handler Handler, mwares ...Middleware) Resource

Post registers a handler for POST-requests

func (Resource) Put

func (r Resource) Put(handler Handler, mwares ...Middleware) Resource

Put registers a handler for PUT-requests

func (Resource) Route

func (r Resource) Route(method method.Method, fun Handler, mwares ...Middleware) Resource

Route is a shortcut to group.Route, providing the extra empty path to the call

func (Resource) Static added in v0.10.5

func (r Resource) Static(prefix, root string) Resource

Static adds a catcher of prefix, that automatically returns files from defined root directory

func (Resource) Trace

func (r Resource) Trace(handler Handler, mwares ...Middleware) Resource

Trace registers a handler for TRACE-requests

func (Resource) Use

func (r Resource) Use(middlewares ...Middleware) Resource

Use applies middlewares to the resource, wrapping all the already registered and registered in future handlers

type Router

type Router struct {
	// contains filtered or unexported fields
}

Router is a built-in routing entity. It provides support for all the methods defined in the methods package, including shortcuts for those. It also supports dynamic routing (enabled automatically if dynamic path template is registered; otherwise more performant static-routing implementation is used). It also provides custom error handlers for any HTTP error that may occur during parsing the request or the routing of it by itself. By default, TRACE requests are supported (if no handler is attached, the request will be automatically processed), OPTIONS (including server-wide ones) and 405 Method Not Allowed errors in compliance with their HTTP semantics.

func New added in v0.8.1

func New() *Router

New constructs a new instance of inbuilt router

func (*Router) Alias added in v0.13.1

func (r *Router) Alias(from, to string) *Router

Alias makes an implicitly redirects to other endpoint by changing request path before a handler is called. In case of implicit redirect, original path is stored in Request.Env.AliasFrom

func (*Router) Catch added in v0.10.5

func (r *Router) Catch(prefix string, handler Handler, middlewares ...Middleware) *Router

Catch registers a catcher. A catcher is a handler, that is being called if requested path is not found, and it starts with a defined prefix

func (*Router) Connect

func (r *Router) Connect(path string, handler Handler, middlewares ...Middleware) *Router

Connect is a shortcut for registering CONNECT-requests

func (*Router) Delete

func (r *Router) Delete(path string, handler Handler, middlewares ...Middleware) *Router

Delete is a shortcut for registering DELETE-requests

func (*Router) Get

func (r *Router) Get(path string, handler Handler, middlewares ...Middleware) *Router

Get is a shortcut for registering GET-requests

func (*Router) Group

func (r *Router) Group(prefix string) *Router

Group creates a new router with pre-defined prefix for all paths. It'll automatically be merged into the head router on server start. Middlewares, applied on this router, will not affect the head router, but initially head router's middlewares will be inherited and will be called in the first order. Registering new error handlers will result in affecting error handlers among ALL the existing groups, including head router

func (*Router) Head

func (r *Router) Head(path string, handler Handler, middlewares ...Middleware) *Router

Head is a shortcut for registering HEAD-requests

func (*Router) Initialize added in v0.16.0

func (r *Router) Initialize() router.Router

func (*Router) Mutator added in v0.15.0

func (r *Router) Mutator(mutator Mutator) *Router

Mutator adds a new mutator.

NOTE: registering them on groups will affect only the order of execution

func (*Router) Options

func (r *Router) Options(path string, handler Handler, middlewares ...Middleware) *Router

Options is a shortcut for registering OPTIONS-requests

func (*Router) Patch

func (r *Router) Patch(path string, handler Handler, middlewares ...Middleware) *Router

Patch is a shortcut for registering PATCH-requests

func (*Router) Post

func (r *Router) Post(path string, handler Handler, middlewares ...Middleware) *Router

Post is a shortcut for registering POST-requests

func (*Router) Put

func (r *Router) Put(path string, handler Handler, middlewares ...Middleware) *Router

Put is a shortcut for registering PUT-requests

func (*Router) Resource

func (r *Router) Resource(path string) Resource

Resource returns a new Resource object for a provided resource path

func (*Router) Route

func (r *Router) Route(
	method method.Method, path string, handlerFunc Handler, middlewares ...Middleware,
) *Router

Route is a base method for registering handlers

func (*Router) RouteError

func (r *Router) RouteError(handler Handler, codes ...status.Code) *Router

RouteError adds an error handler for a corresponding HTTP error code.

The following error codes may be registered:

  • AllErrors (called only if no other error handlers found)
  • status.BadRequest
  • status.NotFound
  • status.MethodNotAllowed
  • status.RequestEntityTooLarge
  • status.CloseConnection
  • status.RequestURITooLong
  • status.HeaderFieldsTooLarge
  • status.HTTPVersionNotSupported
  • status.UnsupportedMediaType
  • status.NotImplemented
  • status.RequestTimeout

Note: if handler returned one of error codes above, error handler WON'T be called. Also, global middlewares, applied to the root router, will also be used for error handlers. However, global middlewares defined on groups won't be used.

WARNING: calling this method from groups will affect ALL routers, including root

func (*Router) Static added in v0.10.5

func (r *Router) Static(prefix, root string, mwares ...Middleware) *Router

Static adds a catcher of prefix, that automatically returns files from defined root directory

func (*Router) Trace

func (r *Router) Trace(path string, handler Handler, middlewares ...Middleware) *Router

Trace is a shortcut for registering TRACE-requests

func (*Router) Use

func (r *Router) Use(middlewares ...Middleware) *Router

Use adds middlewares into the global list of a group's middlewares. But they will be applied only after the server will be started

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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