Middleware

package
v1.4.1 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2023 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func BasicAuthMiddleware added in v1.1.9

func BasicAuthMiddleware(realm string, username, password string) gin.HandlerFunc

BasicAuthMiddleware http基本认证中间件

Example:

r := gin.Default()
r.GET("/secret", BasicAuth("User Login", "admin", "admin"), func(c *gin.Context) {
	c.String(200, "Secret content")
})

func CrossMiddleware added in v1.2.0

func CrossMiddleware() gin.HandlerFunc

CrossMiddleware 跨域中间件

func JsonFormatMiddleware

func JsonFormatMiddleware(CamelCase bool, UrlPrefix string) gin.HandlerFunc

JsonFormatMiddleware

自动将json数据重新转化为驼峰或者下划线

参数1 CamelCase true 驼峰 false 下划线

参数2 UrlPrefix 前缀 作用的url前缀

Example
r := gin.Default()
r.Use(JsonFormatMiddleware(false, "/admin"))
Output:

func JwtVerifyMiddleware

func JwtVerifyMiddleware(RedirectUrl string) gin.HandlerFunc

JwtVerifyMiddleware @description: jwt验证中间件 未授权跳转到登录页面 已授权将uid写入上下文 通过c.Get("uid")获取 @param RedirectUrl string 未授权跳转地址 例如 /admin/login @return gin.HandlerFunc

func LoggerMiddleware

func LoggerMiddleware() gin.HandlerFunc

Types

type ResponseWriterWrapper

type ResponseWriterWrapper struct {
	gin.ResponseWriter
	Body      *bytes.Buffer // 缓存
	CamelCase bool          // 真驼峰 假下划线

}

func (ResponseWriterWrapper) Write

func (w ResponseWriterWrapper) Write(b []byte) (int, error)

func (ResponseWriterWrapper) WriteString

func (w ResponseWriterWrapper) WriteString(s string) (int, error)

Jump to

Keyboard shortcuts

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