middleware

package
v0.0.9 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2024 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AccessLog added in v0.0.6

func AccessLog(appName string) gin.HandlerFunc

AccessLog middleware for request and response body

func AddAccessLogHeader added in v0.0.6

func AddAccessLogHeader(headers []string)

func AddIgnoreTraceLogPath added in v0.0.9

func AddIgnoreTraceLogPath(path string, ignore bool)

func CORS

func CORS() gin.HandlerFunc

CORS gin middleware cors

func GinProxy

func GinProxy[Rsp any](c *gin.Context, host, uri string) (rsp Rsp, err error)

GinProxy gin request proxy and get rsp

func GinPureProxy

func GinPureProxy(c *gin.Context, host string)

GinPureProxy gin request proxy

func Limiter

func Limiter(appName string, rl *limiter.RateLimiter) gin.HandlerFunc

Limiter gin middleware limiter if rl is nil, default Bucket = 1000, Rate = 1000

func Logger added in v0.0.9

func Logger() gin.HandlerFunc

Logger

func Recovery

func Recovery() gin.HandlerFunc

Recovery gin middleware recovery

func SetAccessLogHeader added in v0.0.6

func SetAccessLogHeader(headers []string)

func SetIgnoreTraceLog added in v0.0.9

func SetIgnoreTraceLog(ignore bool)

Types

type CommonRsp added in v0.0.6

type CommonRsp struct {
	Code    int    `json:"code"`
	Message string `json:"message,omitempty"`
	Data    any    `json:"data,omitempty"`
}

type HttpRsp

type HttpRsp[V any] struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
	Data    V      `json:"data,omitempty"`
}

type OutputLog added in v0.0.6

type OutputLog struct {
	// common
	AppName string `json:"app_name"`
	CostMs  int64  `json:"cost_ms"`
	Ts      int64  `json:"ts"`

	// request
	ClientIP  string `json:"client_ip"`
	Method    string `json:"method"`
	Schema    string `json:"schema"`
	Host      string `json:"host"`
	Path      string `json:"path"`
	ReqHeader string `json:"req_header"`
	ReqBody   string `json:"req_body"`

	// response
	StatusCode int    `json:"status_code"`
	ResHeader  string `json:"res_header"`
	ResCode    int    `json:"res_code"`
	ResMsg     string `json:"res_msg"`
	ResBody    string `json:"res_body"`
}

type RecoveryInfo

type RecoveryInfo struct {
	Time        string `json:"time"`
	RequestURI  string `json:"request_uri"`
	Body        string `json:"body"`
	RequestInfo string `json:"request_info"`
	Err         any    `json:"error"`
	Stack       string `json:"stack"`
}

Jump to

Keyboard shortcuts

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