middleware

package
v0.20.2 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package middleware gzip to enable GZIP support. Ref: https://github.com/gin-contrib/gzip

Package middleware pprof serves via its HTTP server runtime profiling data in the format expected by the pprof visualization tool. Ref: https://github.com/gin-contrib/pprof

Package middleware ginzap provides log handling using zap package. Code structure based on ginrus package. Ref: https://github.com/gin-contrib/zap

Index

Constants

View Source
const (
	CorsDefaultAllowOrigin      = "*"
	CorsDefaultAllowMethods     = "GET, POST, PUT, PATCH, DELETE, HEAD, OPTIONS"
	CorsDefaultAllowHeaders     = "Origin, Content-Type, X-CSRF-Token, Authorization, Jwt-Authorization, X-Requested-With, Accept, X-Cookie"
	CorsDefaultExposeHeaders    = "Content-Length, Cache-Control, Content-Language, Content-Type, Expires, Last-Modified, Pragma"
	CorsDefaultAllowCredentials = "true"
	CorsDefaultMaxAge           = "86400"
)
View Source
const (
	// PprofDefaultPrefix url prefix of pprof
	PprofDefaultPrefix = "/debug/pprof"
)

Variables

This section is empty.

Functions

func Cors

func Cors() gin.HandlerFunc

Cors is a middleware function that appends headers to allow CORS with default config

func CorsWithOption

func CorsWithOption(option CorsOption) gin.HandlerFunc

CorsWithOption is a middleware function that appends headers to allow CORS with option

func Ginzap

func Ginzap(logger *zap.Logger, timeFormat string, utc bool) gin.HandlerFunc

Ginzap returns a gin.HandlerFunc (middleware) that logs requests using uber-go/zap.

Requests with errors are logged using zap.Error(). Requests without errors are logged using zap.Info().

It receives:

  1. A time package format string (e.g. time.RFC3339).
  2. A boolean stating whether to use UTC time zone or local.

func GinzapWithConfig

func GinzapWithConfig(logger *zap.Logger, conf *ZapConfig) gin.HandlerFunc

GinzapWithConfig returns a gin.HandlerFunc using configs

func Gzip

func Gzip(level int, options ...gzips.Option) gin.HandlerFunc

func HeaderAuth

func HeaderAuth(k string, v string, json bool) gin.HandlerFunc

HeaderAuth is a middleware function that validates the request header. Return http forbidden code or rest json

func JwtAuth

func JwtAuth(headerKey string, secret string) gin.HandlerFunc

JwtAuth jwt 中间件

func NoCache

func NoCache(c *gin.Context)

NoCache is a middleware function that appends headers

func PprofRegister

func PprofRegister(r *gin.Engine, prefixOptions ...string)

PprofRegister the standard HandlerFuncs from the net/http/pprof package with the provided gin.Engine. prefixOptions is a optional. If not prefixOptions, the default path prefix is used, otherwise first prefixOptions will be path prefix.

func PprofRouteRegister

func PprofRouteRegister(rg *gin.RouterGroup, prefixOptions ...string)

PprofRouteRegister the standard HandlerFuncs from the net/http/pprof package with the provided gin.GrouterGroup. prefixOptions is a optional. If not prefixOptions, the default path prefix is used, otherwise first prefixOptions will be path prefix.

func RestRecovery

func RestRecovery(stack bool) gin.RecoveryFunc

RestRecovery For gin.CustomRecovery

Types

type CorsOption

type CorsOption struct {
	AllowOrigin      string
	AllowMethods     string
	AllowHeaders     string
	ExposeHeaders    string
	AllowCredentials string
	MaxAge           string
}

type ZapConfig

type ZapConfig struct {
	TimeFormat string
	UTC        bool
	SkipPaths  []string
}

ZapConfig is zap config setting for Ginzap

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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