🐛 fix(server): 增加优雅退出与请求超时保护

- 新增 SIGINT/SIGTERM 信号处理与 http.Server.Shutdown,退出前确保统计数据保存、数据库正常关闭
- 为 http.Server 设置 ReadHeaderTimeout/ReadTimeout/WriteTimeout/IdleTimeout,防止慢客户端长期占用连接
- 全局配置指针改为 atomic.Pointer 并提供 GetAppConfig 访问器,消除配置热更新时的数据竞争,同时删除冗余的 manager.config 字段
- 请求统计九组计数器重构为 map[string]*atomic.Int64,统一 incrementStat/getStatsSnapshot 访问,精简约 40 行样板代码
- go mod tidy 清理 go.mod 与 go.sum 中的冗余依赖条目
This commit is contained in:
chenxin committed 2026-09-29 19:47:04 +08:00
1 parent 6981148727
commit d710d382ee
12 files changed
+125 -305

No files matched your search

+4 -7
View File
@@ -10,8 +10,7 @@ import (
// HandleAudio 音频处理
func HandleAudio(w http.ResponseWriter, r *http.Request) {
incrementTotal()
incrementAudio()
incrementStat("total", "audio")
w.Header().Set("Content-Type", "application/json; charset=utf-8")
itemIDs := r.URL.Query().Get("item_ids")
@@ -29,7 +28,7 @@ func HandleAudio(w http.ResponseWriter, r *http.Request) {
// HandleAudioProxy 音频代理处理
func HandleAudioProxy(w http.ResponseWriter, r *http.Request) {
incrementTotal()
incrementStat("total")
// 从URL路径提取key: /audio/proxy/{key}
path := r.URL.Path
@@ -60,8 +59,7 @@ func HandleAudioProxy(w http.ResponseWriter, r *http.Request) {
// HandleVideo 视频处理
func HandleVideo(w http.ResponseWriter, r *http.Request) {
incrementTotal()
incrementVideo()
incrementStat("total", "video")
w.Header().Set("Content-Type", "application/json; charset=utf-8")
itemIDs := r.URL.Query().Get("item_ids")
@@ -77,8 +75,7 @@ func HandleVideo(w http.ResponseWriter, r *http.Request) {
// HandleManga 漫画处理
func HandleManga(w http.ResponseWriter, r *http.Request) {
incrementTotal()
incrementManga()
incrementStat("total", "manga")
itemID := r.URL.Query().Get("item_ids")
if itemID == "" {
itemID = r.URL.Query().Get("item_id")