gm

package module
v0.0.0-...-d86c1a5 Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2024 License: BSD-2-Clause Imports: 13 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Gin Middleware Extension

Gin-Middleware is a middleware extension of the Gin framework in Go, including common functions such as guards, pipes, interceptors, etc.

key features are:

Getting started

Prerequisites

Gin requires Go version 1.21 or above.

Getting Gin-Middleware

With Go's module support, go [build|run|test] automatically fetches the necessary dependencies when you add the import in your code:

import "github.com/zhangyuan722/gin-middleware"

Alternatively, use go get:

go get -u github.com/zhangyuan722/gin-middleware@latest
Test
go test -v

Documentation

Index

Constants

View Source
const (
	CtxQuery = "query"
	CtxBody  = "body"

	CtxBrowserName = "browserName"
	CtxDeviceType  = "deviceType"
	CtxOSName      = "osName"
	CtxOSVersion   = "osVersion"
)
View Source
const (
	DeviceTypeDesktop = "desktop"
	DeviceTypeMobile  = "mobile"
	DeviceTypeTablet  = "tablet"
	DeviceTypeBot     = "bot"
	DeviceTypeUnknown = "unknown"
)
View Source
const (
	CtxClaims = "claims"
)

Variables

This section is empty.

Functions

func AuthGuard

func AuthGuard(p *AuthGuardPayload) gin.HandlerFunc

AuthGuard http router 判断当前请求权限

path 在白名单时跳过验证,可用“*”模糊匹配

func BodyPipe

func BodyPipe[T any]() gin.HandlerFunc

func GenerateToken

func GenerateToken(claims Claims, secretKey string) (string, error)

func LogAlarm

func LogAlarm(p *LogAlarmPayload) gin.HandlerFunc

func QueryPipe

func QueryPipe[T any]() gin.HandlerFunc

func UserAgentPipe

func UserAgentPipe() gin.HandlerFunc

Types

type AlarmTrigger

type AlarmTrigger struct {
	WebHook []string
}

type AuthGuardPayload

type AuthGuardPayload struct {
	RequestHeaderAuthKey string
	WhiteList            []string

	SecretKey string

	CallBack func(c *gin.Context, claims *Claims, accessToken string)
	FailBack func(c *gin.Context, code int, msg string, data any)
}

type Claims

type Claims = jwt.RegisteredClaims

func ParseToken

func ParseToken(tokenString string, secretKey string) (*Claims, error)

type LogAlarmPayload

type LogAlarmPayload struct {
	Trigger AlarmTrigger
	Params  []string
}

type NumericDate

type NumericDate = jwt.NumericDate

func NewNumericDate

func NewNumericDate(t time.Time) *NumericDate

Jump to

Keyboard shortcuts

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