routes

package
v1.4.4 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2022 License: BSD-3-Clause Imports: 11 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CORSMiddleware

func CORSMiddleware(conf CORSConfig) func(c CtrlFunc) CtrlFunc

CORSMiddleware setting Cross-Origin Resource Sharing (CORS)

func RecoveryMiddleware

func RecoveryMiddleware(log logger.Logger) func(c CtrlFunc) CtrlFunc

RecoveryMiddleware recovery go panic and write to log

func ThrottlingMiddleware

func ThrottlingMiddleware(max int64) func(c CtrlFunc) CtrlFunc

ThrottlingMiddleware limits active requests

Types

type CORSConfig

type CORSConfig struct {
	Age     int      `yaml:"age"`
	Origin  []string `yaml:"origin"`
	Methods []string `yaml:"methods"`
	Headers []string `yaml:"headers"`
}

CORSConfig model

type CtrlFunc

type CtrlFunc func(http.ResponseWriter, *http.Request)

CtrlFunc interface of controller

type MiddlFunc

type MiddlFunc func(CtrlFunc) CtrlFunc

MiddlFunc interface of middleware

type Router

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

Router model

func NewRouter

func NewRouter() *Router

NewRouter init new router

func (*Router) Global

func (v *Router) Global(middlewares ...MiddlFunc)

Global add global middlewares

func (*Router) Middlewares

func (v *Router) Middlewares(path string, middlewares ...MiddlFunc)

Middlewares add middlewares to route

func (*Router) NoFoundHandler added in v1.4.3

func (v *Router) NoFoundHandler(call CtrlFunc)

NoFoundHandler handler call if route not found

func (*Router) Route

func (v *Router) Route(path string, ctrl CtrlFunc, methods ...string)

Route add new route

func (*Router) ServeHTTP

func (v *Router) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP http interface

Jump to

Keyboard shortcuts

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