middlewares

package
v4.3.6 Latest Latest
Warning

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

Go to latest
Published: Aug 8, 2025 License: AGPL-3.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Auth

func Auth(c *gin.Context)

Auth 中间件,检查用户是否已登录 如果token为空,则将用户设置为访客 认证成功后,将用户对象设置到上下文中

func AuthAdmin

func AuthAdmin(c *gin.Context)

AuthAdmin 中间件,确保用户是管理员 需要在Auth或Authn中间件之后使用

func AuthNotGuest

func AuthNotGuest(c *gin.Context)

AuthNotGuest 中间件,确保用户不是访客 需要在Auth或Authn中间件之后使用

func Authn

func Authn(c *gin.Context)

Authn 中间件,与Auth类似但不检查用户是否禁用 用于需要认证但允许禁用用户的场景

func Down

func Down(verifyFunc func(string, string) error) func(c *gin.Context)

Down 中间件生成器,用于处理下载请求的验证 验证文件路径和签名

参数:

  • verifyFunc: 签名验证函数,接受路径和签名参数

返回:

  • gin.HandlerFunc: Gin中间件函数

func DownloadRateLimiter

func DownloadRateLimiter(limiter stream.Limiter) gin.HandlerFunc

DownloadRateLimiter 中间件生成器,限制下载速率 包装响应写入器,应用速率限制

参数:

  • limiter: 速率限制器

返回:

  • gin.HandlerFunc: Gin中间件函数

func ErrorLogging

func ErrorLogging() gin.HandlerFunc

ErrorLogging 中间件,记录HTTP响应中的错误信息 捕获响应体中的错误信息或状态码错误,并记录到日志中

返回:

  • gin.HandlerFunc: Gin中间件函数

func FilteredLogger added in v4.2.8

func FilteredLogger() gin.HandlerFunc

func ForceHTTPS

func ForceHTTPS(c *gin.Context)

ForceHTTPS 中间件,强制将HTTP请求重定向到HTTPS 如果请求不是通过HTTPS发起的,则将其重定向到HTTPS版本

参数:

  • c: Gin上下文

func FsUp

func FsUp(c *gin.Context)

FsUp 中间件,处理文件上传请求的权限验证 检查用户是否有权限上传文件到指定路径

func MaxAllowed

func MaxAllowed(n int) gin.HandlerFunc

MaxAllowed 中间件生成器,限制并发请求数量 使用信号量模式实现请求限流

参数:

  • n: 最大并发请求数

返回:

  • gin.HandlerFunc: Gin中间件函数

func SearchIndex

func SearchIndex(c *gin.Context)

SearchIndex 中间件,检查搜索索引是否可用 如果搜索索引设置为"none",则拒绝搜索请求

参数:

  • c: Gin上下文

func StoragesLoaded

func StoragesLoaded(c *gin.Context)

StoragesLoaded 中间件,检查存储是否已加载完成 如果存储尚未加载,除了某些特定路径外,其他请求将被拒绝

允许通过的路径包括: - 根路径和favicon.ico - 静态资源路径(assets、images、streamer、static)

func UploadRateLimiter

func UploadRateLimiter(limiter stream.Limiter) gin.HandlerFunc

UploadRateLimiter 中间件生成器,限制上传速率 包装请求体,应用速率限制

参数:

  • limiter: 速率限制器

返回:

  • gin.HandlerFunc: Gin中间件函数

Types

type ResponseWriterWrapper

type ResponseWriterWrapper struct {
	gin.ResponseWriter           // 原始的响应写入器
	WrapWriter         io.Writer // 包装的写入器
}

ResponseWriterWrapper 响应写入器包装器 将响应写入重定向到自定义的写入器

func (*ResponseWriterWrapper) Write

func (w *ResponseWriterWrapper) Write(p []byte) (n int, err error)

Write 方法重写,将数据写入到包装的写入器

参数:

  • p: 要写入的字节切片

返回:

  • n: 写入的字节数
  • err: 写入错误

Jump to

Keyboard shortcuts

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