完善项目

This commit is contained in:
user123456
2025-06-11 17:52:19 +08:00
parent b2ebcf244a
commit c1ba893a9d
10 changed files with 496 additions and 143 deletions

View File

@@ -1,21 +0,0 @@
FROM golang:1.24-alpine AS builder
WORKDIR /app
COPY go.mod go.sum ./
RUN go mod download
COPY . .
RUN CGO_ENABLED=0 GOOS=linux go build -ldflags="-s -w" -trimpath -o hubproxy .
FROM alpine
WORKDIR /root/
# 安装skopeo
RUN apk add --no-cache skopeo && mkdir -p temp && chmod 700 temp
COPY --from=builder /app/hubproxy .
COPY --from=builder /app/config.toml .
COPY --from=builder /app/public ./public
CMD ["./hubproxy"]

View File

@@ -213,17 +213,17 @@ func enableViperHotReload() {
// 读取配置文件
if err := viperInstance.ReadInConfig(); err != nil {
fmt.Printf("Viper读取配置失败,继续使用当前配置: %v\n", err)
fmt.Printf("读取配置失败,继续使用当前配置: %v\n", err)
return
}
isViperEnabled = true
fmt.Println("🔄 Viper自动热重载已启用")
fmt.Println("自动热重载已启用")
// 🚀 启用文件监听
viperInstance.WatchConfig()
viperInstance.OnConfigChange(func(e fsnotify.Event) {
fmt.Printf("📁 检测到配置文件变化: %s\n", e.Name)
fmt.Printf("检测到配置文件变化: %s\n", e.Name)
hotReloadWithViper()
})
}
@@ -231,14 +231,14 @@ func enableViperHotReload() {
// 🔥 使用Viper进行热重载
func hotReloadWithViper() {
start := time.Now()
fmt.Println("🔄 开始Viper自动热重载...")
fmt.Println("🔄 自动热重载...")
// 创建新配置
cfg := DefaultConfig()
// 使用Viper解析配置到结构体
if err := viperInstance.Unmarshal(cfg); err != nil {
fmt.Printf("❌ Viper配置解析失败: %v\n", err)
fmt.Printf("❌ 配置解析失败: %v\n", err)
return
}

View File

@@ -7,7 +7,7 @@ port = 5000
fileSize = 2147483648
[rateLimit]
# 每个IP每小时允许的请求数
# 每个IP每小时允许的请求数(Docker镜像每个层为一个请求)
requestLimit = 200
# 限流周期(小时)
periodHours = 1.0
@@ -35,9 +35,8 @@ whiteList = []
# 禁止访问黑名单中的仓库/镜像
blackList = [
"baduser/malicious-repo",
"thesadboy/x-ui",
"vaxilu/x-ui",
"vaxilu/*"
"*/malicious-repo",
"baduser/*"
]
[download]
@@ -82,14 +81,9 @@ enabled = true
# authType = "basic"
# enabled = false
# 缓存配置Token和Manifest统一管理显著提升性能
# 缓存配置:Docker临时Token和Manifest统一管理显著提升性能
[tokenCache]
# 是否启用缓存(同时控制Token和Manifest缓存)
enabled = true
# 默认缓存时间适用于mutable标签如latest等
# 默认缓存时间
defaultTTL = "20m"
# 说明:
# - immutable digest缓存24小时
# - latest/main等热门标签缓存5分钟
# - 普通tag使用defaultTTL
# - Token自动从响应中提取TTL

View File

@@ -1,8 +0,0 @@
services:
ghproxy:
build: .
restart: always
ports:
- '5000:5000'
volumes:
- ./config.toml:/root/config.toml

View File

@@ -23,7 +23,7 @@ var smartLimiter = &SmartRateLimit{}
// 硬编码的智能限流参数 - 无需配置管理
const (
// manifest请求后的活跃窗口时间
activeWindowDuration = 5 * time.Minute
activeWindowDuration = 3 * time.Minute
// 活跃窗口内最大免费blob请求数(防止滥用)
maxFreeBlobRequests = 100
// 会话清理间隔