routes

package
v1.3.4 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2021 License: BSD-3-Clause Imports: 7 Imported by: 0

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 SplitURI

func SplitURI(uri string) []string

func ThrottlingMiddleware

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

Throttling limits active requests

Types

type CORSConfig

type CORSConfig struct {
	Age     int
	Origin  []string
	Methods []string
	Headers []string
}

CORSConfig model

type CtrlFunc

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

CtrlFunc interface of controller

type Handler

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

Handler model

func NewHandler

func NewHandler() *Handler

NewHandler getting new handler

func (*Handler) Match

func (h *Handler) Match(uris []string, pos int, method string) (code int, ctrl CtrlFunc, midd []MiddlFunc)

Match find route in tree

func (*Handler) Middlewares

func (h *Handler) Middlewares(uris []string, pos int, middlewares []MiddlFunc)

Middlewares add middleware to route

func (*Handler) Route

func (h *Handler) Route(uris []string, pos int, ctrl CtrlFunc, methods []string)

Route add new route

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 (o *Router) Global(middlewares ...MiddlFunc)

Global add global middlewares

func (*Router) Middlewares

func (o *Router) Middlewares(prefix string, middlewares ...MiddlFunc)

Middlewares add middlewares to route

func (*Router) Route

func (o *Router) Route(uri string, cb CtrlFunc, methods ...string)

Route add new route

func (*Router) ServeHTTP

func (o *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