router

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: May 21, 2022 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package router routes requests

Index

Constants

View Source
const ErrInvalidRequest = errors.Code("invalid_request")

ErrInvalidRequest is returned when the request is not valid

Variables

This section is empty.

Functions

This section is empty.

Types

type Binder

type Binder func([]byte, interface{}) error

Binder is used to bind a body to a struct, the output must be a pointer

type Context

type Context interface {
	Request() *http.Request
	Writer() http.ResponseWriter
	PathParams() httprouter.Params
	Get(string) interface{}
	Set(string, interface{})
	Empty(int) error
	JSON(int, interface{}) error
	Bind(out interface{}, validators ...Validator) error
	BindQuery(out interface{}, validators ...Validator) error
}

Context holds data about the request and provides convenience methods for responding

func NewContext

func NewContext(request *http.Request, rw http.ResponseWriter, p httprouter.Params) Context

NewContext creates a new context

type DELETE

type DELETE interface {
	Delete(Context) error
}

DELETE handles DELETE HTTP Methods

type GET

type GET interface {
	Get(Context) error
}

GET handles GET HTTP Methods

type Middleware

type Middleware func(Route) Route

Middleware wraps handler calls

type OPTIONS

type OPTIONS interface {
	Options(Context) error
}

OPTIONS handles OPTIONS HTTP Methods

type PATCH

type PATCH interface {
	Patch(Context) error
}

PATCH handles PATCH HTTP Methods

type POST

type POST interface {
	Post(Context) error
}

POST handles POST HTTP Methods

type PUT

type PUT interface {
	Put(Context) error
}

PUT handles PUT HTTP Methods

type Route

type Route func(Context) error

Route is the actual function call

type Router

type Router struct {
	// Middlewares that are applied to all routes, before a route's middleware
	Middlewares []Middleware
	// Translator is used to translate error messages returned by the Routes
	Translator errors.Translator
	// contains filtered or unexported fields
}

Router wraps an http router

func New

func New() *Router

New creates a router

func (*Router) Add

func (r *Router) Add(path string, route interface{}, middlewares ...Middleware)

Add registers a route with the router

The global middlewares that will be used are the ones currently set with the Router instance Changing them later on will not affect the route

func (*Router) Function

func (r *Router) Function() func(http.ResponseWriter, *http.Request)

Function returns a function that is usable with cloud functions

type Validator

type Validator func(interface{}) error

Validator should return an error if the input is not valid

Directories

Path Synopsis
Package middleware has a set of commonly used middlewares
Package middleware has a set of commonly used middlewares
rate
Package rate offers a rate limiter middleware
Package rate offers a rate limiter middleware

Jump to

Keyboard shortcuts

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