mirror of
https://github.com/acepanel/panel.git
synced 2026-02-04 07:57:21 +08:00
* Initial plan * feat: add date selector for log viewing - Add date parameter to log list API - Add log dates listing API - Update frontend with date selector in all log views - Add translations for Date field Co-authored-by: devhaozi <115467771+devhaozi@users.noreply.github.com> * refactor: cache regex patterns to avoid recompilation overhead Co-authored-by: devhaozi <115467771+devhaozi@users.noreply.github.com> * refactor: use predefined regex constants instead of sync.Map Simplified the regex caching by using predefined package-level constants for the three log types (app, db, http) instead of sync.Map. Co-authored-by: devhaozi <115467771+devhaozi@users.noreply.github.com> * fix: lint --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: devhaozi <115467771+devhaozi@users.noreply.github.com> Co-authored-by: 耗子 <haozi@loli.email>
58 lines
1.1 KiB
Go
58 lines
1.1 KiB
Go
package service
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/acepanel/panel/internal/biz"
|
|
"github.com/acepanel/panel/internal/http/request"
|
|
)
|
|
|
|
type LogService struct {
|
|
logRepo biz.LogRepo
|
|
}
|
|
|
|
func NewLogService(logRepo biz.LogRepo) *LogService {
|
|
return &LogService{
|
|
logRepo: logRepo,
|
|
}
|
|
}
|
|
|
|
// List 获取日志列表
|
|
func (s *LogService) List(w http.ResponseWriter, r *http.Request) {
|
|
req, err := Bind[request.LogList](r)
|
|
if err != nil {
|
|
Error(w, http.StatusUnprocessableEntity, "%v", err)
|
|
return
|
|
}
|
|
|
|
// 默认限制
|
|
if req.Limit == 0 {
|
|
req.Limit = 100
|
|
}
|
|
|
|
entries, err := s.logRepo.List(req.Type, req.Limit, req.Date)
|
|
if err != nil {
|
|
Error(w, http.StatusInternalServerError, "%v", err)
|
|
return
|
|
}
|
|
|
|
Success(w, entries)
|
|
}
|
|
|
|
// Dates 获取日志日期列表
|
|
func (s *LogService) Dates(w http.ResponseWriter, r *http.Request) {
|
|
req, err := Bind[request.LogDates](r)
|
|
if err != nil {
|
|
Error(w, http.StatusUnprocessableEntity, "%v", err)
|
|
return
|
|
}
|
|
|
|
dates, err := s.logRepo.ListDates(req.Type)
|
|
if err != nil {
|
|
Error(w, http.StatusInternalServerError, "%v", err)
|
|
return
|
|
}
|
|
|
|
Success(w, dates)
|
|
}
|