- 新增 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 中的冗余依赖条目
45 lines
1.2 KiB
Go
45 lines
1.2 KiB
Go
package handlers
|
|
|
|
import (
|
|
"fanqie/internal/fqapi"
|
|
"fmt"
|
|
"net/http"
|
|
)
|
|
|
|
// HandleCategoryFront 分类列表处理
|
|
func HandleCategoryFront(w http.ResponseWriter, r *http.Request) {
|
|
incrementStat("total", "category")
|
|
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
|
|
|
tab := r.URL.Query().Get("tab")
|
|
|
|
result, err := fqapi.HandleCategoryFront(tab)
|
|
if err != nil {
|
|
fmt.Fprintf(w, `{"code": -1, "msg": "获取分类列表失败: %s"}`, err.Error())
|
|
return
|
|
}
|
|
|
|
fmt.Fprint(w, result)
|
|
}
|
|
|
|
// HandleCategoryLanding 分类详情处理
|
|
func HandleCategoryLanding(w http.ResponseWriter, r *http.Request) {
|
|
incrementStat("total", "category")
|
|
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
|
|
|
categoryID := r.URL.Query().Get("category_id")
|
|
offset := r.URL.Query().Get("offset")
|
|
wordNumber := r.URL.Query().Get("word_number")
|
|
bookStatus := r.URL.Query().Get("book_status")
|
|
sortBy := r.URL.Query().Get("sort_by")
|
|
|
|
result, err := fqapi.HandleCategoryLanding(categoryID, offset, wordNumber, bookStatus, sortBy)
|
|
if err != nil {
|
|
fmt.Fprintf(w, `{"code": -1, "msg": "获取分类详情失败: %s"}`, err.Error())
|
|
return
|
|
}
|
|
|
|
fmt.Fprint(w, result)
|
|
}
|
|
|