refactor: remove dead code package internal/middleware/limitrate
This commit is contained in:
parent
5066a1a64c
commit
a919369ca4
@ -1,24 +0,0 @@
|
||||
// Package limitrate 提供基于令牌桶算法的请求速率限制功能。
|
||||
//
|
||||
// 包含速率限制器相关的逻辑,用于控制请求处理速率。
|
||||
//
|
||||
// 作者:xfy
|
||||
package limitrate
|
||||
|
||||
import (
|
||||
"rua.plus/lolly/internal/config"
|
||||
)
|
||||
|
||||
const (
|
||||
// LargeFileStrategySkip 大文件策略:跳过(不限制)。
|
||||
LargeFileStrategySkip = "skip"
|
||||
// LargeFileStrategyCoarse 大文件策略:粗略限制。
|
||||
LargeFileStrategyCoarse = "coarse"
|
||||
)
|
||||
|
||||
// Middleware 速率限制中间件
|
||||
type Middleware struct {
|
||||
config *config.LimitRateConfig
|
||||
}
|
||||
|
||||
|
||||
@ -1,19 +0,0 @@
|
||||
// Package limitrate 提供响应速率限制中间件的测试。
|
||||
//
|
||||
// 该文件测试速率限制模块的各项功能,包括:
|
||||
// - 常量值
|
||||
//
|
||||
// 作者:xfy
|
||||
package limitrate
|
||||
|
||||
import "testing"
|
||||
|
||||
// TestConstants 测试常量值。
|
||||
func TestConstants(t *testing.T) {
|
||||
if LargeFileStrategySkip != "skip" {
|
||||
t.Errorf("LargeFileStrategySkip = %q, want %q", LargeFileStrategySkip, "skip")
|
||||
}
|
||||
if LargeFileStrategyCoarse != "coarse" {
|
||||
t.Errorf("LargeFileStrategyCoarse = %q, want %q", LargeFileStrategyCoarse, "coarse")
|
||||
}
|
||||
}
|
||||
@ -1,24 +0,0 @@
|
||||
// Package limitrate 提供基于令牌桶算法的请求速率限制功能。
|
||||
//
|
||||
// 包含速率限制响应写入器相关的逻辑,用于处理被限制的请求响应。
|
||||
//
|
||||
// 作者:xfy
|
||||
package limitrate
|
||||
|
||||
import (
|
||||
"io"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
// RateLimitedWriter 限速写入器,使用令牌桶算法
|
||||
type RateLimitedWriter struct {
|
||||
writer io.Writer
|
||||
rate int64 // 字节/秒
|
||||
bucket int64 // 当前令牌数
|
||||
maxBucket int64 // 令牌桶最大容量
|
||||
lastTime time.Time // 上次更新时间
|
||||
mu sync.Mutex
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user