middleware

package
v0.0.0-...-6de7cd6 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2020 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RealIP

func RealIP(h http.Handler) http.Handler

RealIP is a middleware that sets a http.Request's RemoteAddr to the results of parsing either the X-Forwarded-For header or the X-Real-IP header (in that order).

This middleware should be inserted fairly early in the middleware stack to ensure that subsequent layers (e.g., request loggers) which examine the RemoteAddr will see the intended value.

You should only use this middleware if you can trust the headers passed to you (in particular, the two headers this middleware uses), for example because you have placed a reverse proxy like HAProxy or nginx in front of chi. If your reverse proxies are configured to pass along arbitrary header values from the client, or if you use this middleware without a reverse proxy, malicious clients will be able to make you very sad (or, depending on how you're using RemoteAddr, vulnerable to an attack of some sort).

func TimeoutHandler

func TimeoutHandler(timeout time.Duration) func(next http.Handler) http.Handler

TimeoutHandler server timeout middleware wraps the request context with a timeout 中间件参考go-chi/chi库 https://github.com/go-chi/chi/blob/master/middleware/timeout.go return http.Handler处理器,服务端超时中间件,可以根据实际情况添加这个中间件

func TimeoutHandlerFunc

func TimeoutHandlerFunc(timeout time.Duration, h http.HandlerFunc) http.HandlerFunc

TimeoutHandlerFunc 单独对处理器函数做超时限制 return http.HandlerFunc,服务端超时中间件,可以根据实际情况添加这个中间件

Types

type RequestWare

type RequestWare struct{}

RequestWare request middleware.

func (*RequestWare) AccessLog

func (reqWare *RequestWare) AccessLog(h http.Handler) http.Handler

AccessLog 访问日志

func (*RequestWare) NotFoundHandler

func (reqWare *RequestWare) NotFoundHandler(w http.ResponseWriter, r *http.Request)

NotFoundHandler 404处理函数

func (*RequestWare) Recover

func (reqWare *RequestWare) Recover(h http.Handler) http.Handler

Recover 当请求发生了异常或致命错误,需要捕捉r,w执行上下文的错误 该Recover设计灵感来源于golang gin框架的WriteHeaderNow()设计

Jump to

Keyboard shortcuts

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