feat: add a service for periodic cleanup of error accounts based on configuration.
This commit is contained in:
@@ -104,8 +104,9 @@ func startServer(cfg *config.Config) {
|
||||
// 日志 API
|
||||
mux.HandleFunc("/api/logs", api.CORS(handleGetLogs))
|
||||
mux.HandleFunc("/api/logs/clear", api.CORS(handleClearLogs))
|
||||
mux.HandleFunc("/api/logs/query", api.CORS(handleQueryLogs)) // 按模块查询日志
|
||||
mux.HandleFunc("/api/logs/stream", handleLogStream) // SSE 实时日志
|
||||
mux.HandleFunc("/api/logs/clear-module", api.CORS(handleClearLogsByModule)) // 按模块清除日志
|
||||
mux.HandleFunc("/api/logs/query", api.CORS(handleQueryLogs)) // 按模块查询日志
|
||||
mux.HandleFunc("/api/logs/stream", handleLogStream) // SSE 实时日志
|
||||
|
||||
// S2A 代理 API
|
||||
mux.HandleFunc("/api/s2a/test", api.CORS(handleS2ATest))
|
||||
@@ -296,6 +297,26 @@ func handleClearLogs(w http.ResponseWriter, r *http.Request) {
|
||||
api.Success(w, map[string]string{"message": "日志已清空"})
|
||||
}
|
||||
|
||||
// handleClearLogsByModule POST /api/logs/clear-module?module=cleaner
|
||||
func handleClearLogsByModule(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method != http.MethodPost {
|
||||
api.Error(w, http.StatusMethodNotAllowed, "仅支持 POST")
|
||||
return
|
||||
}
|
||||
|
||||
module := r.URL.Query().Get("module")
|
||||
if module == "" {
|
||||
api.Error(w, http.StatusBadRequest, "缺少 module 参数")
|
||||
return
|
||||
}
|
||||
|
||||
cleared := logger.ClearLogsByModule(module)
|
||||
api.Success(w, map[string]interface{}{
|
||||
"message": fmt.Sprintf("已清除 %d 条 %s 日志", cleared, module),
|
||||
"cleared": cleared,
|
||||
})
|
||||
}
|
||||
|
||||
// handleQueryLogs GET /api/logs/query?module=cleaner&page=1&page_size=5
|
||||
func handleQueryLogs(w http.ResponseWriter, r *http.Request) {
|
||||
module := r.URL.Query().Get("module")
|
||||
|
||||
Reference in New Issue
Block a user