middleware

package
v0.24.0 Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2022 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 added in v0.24.0

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 added in v0.21.0

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 added in v0.19.0

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 added in v0.3.0

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 added in v0.3.0

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 added in v0.16.0

func RestRecovery(stack bool) gin.RecoveryFunc

RestRecovery For gin.CustomRecovery

Types

type CorsOption added in v0.24.0

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

type ZapConfig added in v0.15.0

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