middleware

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const AdminRoleName = "admin"
View Source
const UserRoleName = "user"

Variables

This section is empty.

Functions

func Casbin

func Casbin() gin.HandlerFunc

func GalleryPermission

func GalleryPermission() gin.HandlerFunc

func JWT

func JWT(config *config.JWTConfig) gin.HandlerFunc

JWT 认证中间件

func RateLimit

func RateLimit(config *RateLimitConfig) gin.HandlerFunc

RateLimit 速率限制中间件

Types

type FileProgress

type FileProgress struct {
	FileName string
	FileSize int64
	Readed   int64
	UploadID string
	LastSent time.Time
}

FileProgress 跟踪单个文件的上传进度

type ProgressReader

type ProgressReader struct {
	Size      int64
	Readed    int64
	UserID    uint
	Hub       *websocket.Hub
	LastSent  time.Time
	TotalSent bool
	// contains filtered or unexported fields
}

ProgressReader 包装了io.Reader,用于跟踪文件读取进度

func (*ProgressReader) Close

func (pr *ProgressReader) Close() error

Close 实现io.Closer接口,关闭底层的reader

func (*ProgressReader) Read

func (pr *ProgressReader) Read(p []byte) (n int, err error)

Read 实现io.Reader接口,读取数据并发送进度通知

type RateLimitConfig

type RateLimitConfig struct {
	Limit      int                       // 时间窗口内允许的最大请求数
	WindowSize time.Duration             // 时间窗口大小
	KeyFunc    func(*gin.Context) string // 生成速率限制键的函数
}

RateLimitConfig 速率限制配置

type RateLimiter

type RateLimiter struct {
	// contains filtered or unexported fields
}

RateLimiter 速率限制器

func NewRateLimiter

func NewRateLimiter(config *RateLimitConfig) *RateLimiter

NewRateLimiter 创建新的速率限制器

func (*RateLimiter) Allow

func (rl *RateLimiter) Allow(key string) bool

Allow 检查是否允许请求

type UploadProgressMiddleware

type UploadProgressMiddleware struct {
	Hub *websocket.Hub
}

UploadProgressMiddleware 上传进度跟踪中间件

func NewUploadProgressMiddleware

func NewUploadProgressMiddleware(hub *websocket.Hub) *UploadProgressMiddleware

NewUploadProgressMiddleware 创建上传进度中间件实例

func (*UploadProgressMiddleware) Handle

Handle 处理上传进度跟踪

Jump to

Keyboard shortcuts

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