middleware

package
v1.3.6 Latest Latest
Warning

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

Go to latest
Published: May 22, 2024 License: MIT Imports: 46 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PrefixUserID = "u_"
	PrefixRoleID = "r_"
)

Variables

View Source
var AllUrls []string
View Source
var IpLimit []LimitObj

Store session存储

View Source
var UserLimit []LimitObj

Functions

func CSRFCheck

func CSRFCheck() gin.HandlerFunc

CSRFCheck 检查CSRF标记

func CSRFInit

func CSRFInit() gin.HandlerFunc

CSRFInit 初始化CSRF标记

func CacheControl

func CacheControl() gin.HandlerFunc

CacheControl 屏蔽客户端缓存

func CaptchaRequired

func CaptchaRequired(configName string) gin.HandlerFunc

CaptchaRequired 验证请求签名

func CasbinCheckPermission

func CasbinCheckPermission(userID, url, methodtype string) (bool, error)

检查用户是否有权限

func CasbinMiddleware

func CasbinMiddleware(skipper ...SkipperFunc) gin.HandlerFunc

CasbinMiddleware casbin中间件

func CheckUrlLimit

func CheckUrlLimit(r *ratelimit.Rule, item string) (err error)

func ContextWithSpan

func ContextWithSpan(c *gin.Context) (ctx context.Context, ok bool)

ContextWithSpan 返回context

func CurrentUser

func CurrentUser() gin.HandlerFunc

CurrentUser 获取登录用户

func DisableLog

func DisableLog() core.HandlerFunc

func EcmTokenAuth added in v1.2.6

func EcmTokenAuth(skipper ...SkipperFunc) gin.HandlerFunc

Ecm云文档接口检查,获取登录token

func GetEcmUserLoginIntegrationByUserLoginNameV added in v1.3.2

func GetEcmUserLoginIntegrationByUserLoginNameV(c *gin.Context) (string, error)

func GetEcmUserLoginIntegrationByUserLoginNameV1 added in v1.3.2

func GetEcmUserLoginIntegrationByUserLoginNameV1(c *gin.Context, urlHost, secretKey string) (string, error)

GetEcmToken

TODO: 获取 token,存在漏洞,当token在接口调试的过程中,通过接口获取token一定会被替换掉,则toke无法使用;
1、需要手动删除redis 中的token缓存才能生效
⚠️:正式环境上线后,不允许手动调用token接口进行调试, 除非添加 token 校验策略: 用于判断token的有效性;

func HashID

func HashID(IDType int) gin.HandlerFunc

HashID 将给定对象的HashID转换为真实ID

func Init

func Init(urls []string)

模拟用户访问并打印

func JWTAuth

func JWTAuth(skipper ...SkipperFunc) gin.HandlerFunc

JWTAuth 中间件,检查token

func ManualEmptyVisitorRecord

func ManualEmptyVisitorRecord(c *gin.Context)

func NewTracer

func NewTracer(servicename string, addr string) (opentracing.Tracer, io.Closer, error)

NewTracer 创建一个jaeger Tracer

func NoMethodHandler

func NoMethodHandler() gin.HandlerFunc

NoMethodHandler 未找到请求方法的处理函数

func NoRouteHandler

func NoRouteHandler() gin.HandlerFunc

NoRouteHandler 未找到请求路由的处理函数

func OBSAuth

func OBSAuth(skipper ...SkipperFunc) gin.HandlerFunc

func RateLimit

func RateLimit(skipper ...SkipperFunc) gin.HandlerFunc

func RecoveryMiddleware

func RecoveryMiddleware() gin.HandlerFunc

func RecoveryMiddlewareOld

func RecoveryMiddlewareOld() gin.HandlerFunc

func Session

func Session(secret string) gin.HandlerFunc

Session 初始化session

func SetSamplingFrequency

func SetSamplingFrequency(n int)

SetSamplingFrequency 设置采样频率 0 <= n <= 100

func SignMiddleware

func SignMiddleware(headerKeys []string, urlStr string) gin.HandlerFunc

SignMiddleware 生成签名中间件函数 headerKeys 不同接口对应不同请求头,需查看 财务云 接口文件进行传输

func SignMiddlewareV2

func SignMiddlewareV2(headerKeys []string, bodyBytes []byte) gin.HandlerFunc

SignMiddleware 生成签名中间件函数 headerKeys 不同接口对应不同请求头,需查看 财务云 接口文件进行传输

func TracerWrapper

func TracerWrapper(c *gin.Context)

TracerWrapper tracer 中间件

Types

type AdminUserRole

type AdminUserRole struct {
	ID     int64 `gorm:"column:id;primary_key;AUTO_INCREMENT" form:"id"   json:"id"`
	UserID int64 `gorm:"column:user_id;not null;"` // 管理员ID
	RoleID int64 `gorm:"column:role_id;not null;"` // 角色ID
}

type LimitObj

type LimitObj struct {
	Item      string          `json:"item"`
	LimitRule *ratelimit.Rule `json:"limit_rule"`
}
var UrlLimit LimitObj

步骤一:初始化

func CheckUserOrIpLimit

func CheckUserOrIpLimit(limitList []LimitObj, item string, url string) (limit LimitObj, err error)

type SkipperFunc

type SkipperFunc func(*gin.Context) bool

SkipperFunc 定义中间件跳过函数

func AllowPathPrefixNoSkipper

func AllowPathPrefixNoSkipper(prefixes ...string) SkipperFunc

AllowPathPrefixNoSkipper 检查请求路径是否包含指定的前缀,如果包含则不跳过

func AllowPathPrefixSkipper

func AllowPathPrefixSkipper(prefixes ...string) SkipperFunc

AllowPathPrefixSkipper 检查请求路径是否包含指定的前缀,如果包含则跳过

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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