From 963d36592fed3bf9074d571430396db5a856875b Mon Sep 17 00:00:00 2001 From: timerzz Date: Mon, 2 Dec 2024 19:07:39 +0800 Subject: [PATCH] =?UTF-8?q?feat=20=E6=94=AF=E6=8C=81=E8=B9=B2=E5=BA=93?= =?UTF-8?q?=E5=AD=98=E5=92=8C=E5=8E=86=E5=8F=B2=E5=BA=93=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmd/watcher.go | 1 + go.mod | 4 ++-- go.sum | 6 ++---- service/tracer_svc.go | 43 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 48 insertions(+), 6 deletions(-) create mode 100644 service/tracer_svc.go diff --git a/cmd/watcher.go b/cmd/watcher.go index c713129..05aff39 100644 --- a/cmd/watcher.go +++ b/cmd/watcher.go @@ -37,6 +37,7 @@ func main() { svc := []web.Register{ web.NewProbe(), service.NewWatcher(stg), + service.NewTracer(stg), } for _, s := range svc { diff --git a/go.mod b/go.mod index b069b17..d7912d0 100644 --- a/go.mod +++ b/go.mod @@ -3,9 +3,10 @@ module gitea.timerzz.com/kedaya_haitao/watcher go 1.22.2 require ( - gitea.timerzz.com/kedaya_haitao/common v0.0.0-20241130064301-cd385c31e7f1 + gitea.timerzz.com/kedaya_haitao/common v0.0.0-20241202091018-277d73739be8 github.com/gofiber/fiber/v3 v3.0.0-beta.3 github.com/golang/glog v1.2.1 + gorm.io/gorm v1.25.10 ) require ( @@ -34,5 +35,4 @@ require ( golang.org/x/text v0.16.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect gorm.io/driver/postgres v1.5.7 // indirect - gorm.io/gorm v1.25.10 // indirect ) diff --git a/go.sum b/go.sum index 25c86a8..5f0b0cf 100644 --- a/go.sum +++ b/go.sum @@ -1,7 +1,5 @@ -gitea.timerzz.com/kedaya_haitao/common v0.0.0-20241129125918-50b9ed22adb2 h1:gRKzV+KtHoT126BXcaulTarAqmpNgTX9GS6m34NyrRI= -gitea.timerzz.com/kedaya_haitao/common v0.0.0-20241129125918-50b9ed22adb2/go.mod h1:BIz+IMGznPiyLnV1+Ntw1zf8rEIcbymmGq+EfvDsSgE= -gitea.timerzz.com/kedaya_haitao/common v0.0.0-20241130064301-cd385c31e7f1 h1:Z396pRoGvXpVYqD2itlvEOxUt1ZHTyQHLbZzKcVFVGI= -gitea.timerzz.com/kedaya_haitao/common v0.0.0-20241130064301-cd385c31e7f1/go.mod h1:BIz+IMGznPiyLnV1+Ntw1zf8rEIcbymmGq+EfvDsSgE= +gitea.timerzz.com/kedaya_haitao/common v0.0.0-20241202091018-277d73739be8 h1:AJo3Y3icJb8wcjeSnx6SjkHFdBKYm5lFscEuo6O4dDM= +gitea.timerzz.com/kedaya_haitao/common v0.0.0-20241202091018-277d73739be8/go.mod h1:BIz+IMGznPiyLnV1+Ntw1zf8rEIcbymmGq+EfvDsSgE= github.com/andybalholm/brotli v1.1.0 h1:eLKJA0d02Lf0mVpIDgYnqXcUn0GqVmEFny3VuID1U3M= github.com/andybalholm/brotli v1.1.0/go.mod h1:sms7XGricyQI9K10gOSf56VKKWS4oLer58Q+mhRPtnY= github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= diff --git a/service/tracer_svc.go b/service/tracer_svc.go new file mode 100644 index 0000000..eadc0fb --- /dev/null +++ b/service/tracer_svc.go @@ -0,0 +1,43 @@ +package service + +import ( + "gitea.timerzz.com/kedaya_haitao/common/pkg/web" + "gitea.timerzz.com/kedaya_haitao/common/structs/storage" + "github.com/gofiber/fiber/v3" + "gorm.io/gorm" +) + +type Tracer struct { + storage *storage.Storage +} + +func NewTracer(storage *storage.Storage) *Tracer { + return &Tracer{ + storage: storage, + } +} + +func (s *Tracer) Registry(r fiber.Router) { + api := r.Group("/api/v2") + api.Get("tracers", s.List) +} + +func (s *Tracer) List(c fiber.Ctx) error { + var q storage.GetProviderArticleQuery + if err := c.Bind().Query(&q); err != nil { + return err + } + q.TraceAtsNotNull = true + var query = storage.NewPageListQuery(&q) + if err := c.Bind().Query(query); err != nil { + return err + } + articles, total, err := s.storage.ProviderArticle().List(*query, func(db *gorm.DB) *gorm.DB { + db = db.Preload("HistoryAts") + return db + }) + if err != nil { + return err + } + return c.JSON(web.NewResponse(web.NewListResponse(total, articles))) +}