This commit is contained in:
parent
6c9da2c382
commit
5859498a89
@ -2,6 +2,7 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"flag"
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
|
|
||||||
@ -17,6 +18,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
flag.Parse()
|
||||||
glog.Info(">>> BEGIN INIT<<<")
|
glog.Info(">>> BEGIN INIT<<<")
|
||||||
|
|
||||||
ctx, cancel := signal.NotifyContext(context.Background(), os.Kill, os.Interrupt)
|
ctx, cancel := signal.NotifyContext(context.Background(), os.Kill, os.Interrupt)
|
||||||
|
2
go.mod
2
go.mod
@ -3,7 +3,7 @@ module gitea.timerzz.com/kedaya_haitao/provider
|
|||||||
go 1.22.5
|
go 1.22.5
|
||||||
|
|
||||||
require (
|
require (
|
||||||
gitea.timerzz.com/kedaya_haitao/common v0.0.0-20240901105924-1290c1e1fd6a
|
gitea.timerzz.com/kedaya_haitao/common v0.0.0-20240913121100-f0a601466ba1
|
||||||
github.com/gofiber/fiber/v3 v3.0.0-beta.3
|
github.com/gofiber/fiber/v3 v3.0.0-beta.3
|
||||||
github.com/golang/glog v1.2.1
|
github.com/golang/glog v1.2.1
|
||||||
github.com/henrylee2cn/ameda v1.4.10
|
github.com/henrylee2cn/ameda v1.4.10
|
||||||
|
4
go.sum
4
go.sum
@ -1,5 +1,5 @@
|
|||||||
gitea.timerzz.com/kedaya_haitao/common v0.0.0-20240901105924-1290c1e1fd6a h1:BAsCJt5lj0L23qCzfy6dPhfDxoKrW64KxQtXTjuXfaA=
|
gitea.timerzz.com/kedaya_haitao/common v0.0.0-20240913121100-f0a601466ba1 h1:5Bu3V2w4Jd7mgFIeH8GkVaEfvOXIFtPSoApwzsmp9rc=
|
||||||
gitea.timerzz.com/kedaya_haitao/common v0.0.0-20240901105924-1290c1e1fd6a/go.mod h1:BIz+IMGznPiyLnV1+Ntw1zf8rEIcbymmGq+EfvDsSgE=
|
gitea.timerzz.com/kedaya_haitao/common v0.0.0-20240913121100-f0a601466ba1/go.mod h1:BIz+IMGznPiyLnV1+Ntw1zf8rEIcbymmGq+EfvDsSgE=
|
||||||
github.com/andybalholm/brotli v1.1.0 h1:eLKJA0d02Lf0mVpIDgYnqXcUn0GqVmEFny3VuID1U3M=
|
github.com/andybalholm/brotli v1.1.0 h1:eLKJA0d02Lf0mVpIDgYnqXcUn0GqVmEFny3VuID1U3M=
|
||||||
github.com/andybalholm/brotli v1.1.0/go.mod h1:sms7XGricyQI9K10gOSf56VKKWS4oLer58Q+mhRPtnY=
|
github.com/andybalholm/brotli v1.1.0/go.mod h1:sms7XGricyQI9K10gOSf56VKKWS4oLer58Q+mhRPtnY=
|
||||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
|
@ -3,6 +3,7 @@ package service
|
|||||||
import (
|
import (
|
||||||
"gitea.timerzz.com/kedaya_haitao/common/pkg/web"
|
"gitea.timerzz.com/kedaya_haitao/common/pkg/web"
|
||||||
"gitea.timerzz.com/kedaya_haitao/common/structs/storage"
|
"gitea.timerzz.com/kedaya_haitao/common/structs/storage"
|
||||||
|
"gitea.timerzz.com/kedaya_haitao/common/structs/utils"
|
||||||
v2 "gitea.timerzz.com/kedaya_haitao/common/structs/v2"
|
v2 "gitea.timerzz.com/kedaya_haitao/common/structs/v2"
|
||||||
"github.com/gofiber/fiber/v3"
|
"github.com/gofiber/fiber/v3"
|
||||||
"github.com/henrylee2cn/ameda"
|
"github.com/henrylee2cn/ameda"
|
||||||
@ -21,10 +22,13 @@ func NewProvider(storage *storage.Storage) *Provider {
|
|||||||
func (s *Provider) Registry(r fiber.Router) {
|
func (s *Provider) Registry(r fiber.Router) {
|
||||||
api := r.Group("/api/v2")
|
api := r.Group("/api/v2")
|
||||||
api.Get("providers", s.ListProviders)
|
api.Get("providers", s.ListProviders)
|
||||||
api.Get("/providers/:id", s.GetProvider)
|
api.Get("providers/find", s.FindSellers)
|
||||||
|
api.Get("providers/:id", s.GetProvider)
|
||||||
api.Post("providers", s.CreateProvider)
|
api.Post("providers", s.CreateProvider)
|
||||||
api.Put("providers", s.UpdateProvider)
|
api.Put("providers", s.UpdateProvider)
|
||||||
api.Delete("/providers/:id", s.DeleteProvider)
|
api.Delete("providers/:id", s.DeleteProvider)
|
||||||
|
|
||||||
|
api.Get("providers/dict/status", s.DictStatus)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Provider) ListProviders(c fiber.Ctx) error {
|
func (s *Provider) ListProviders(c fiber.Ctx) error {
|
||||||
@ -81,6 +85,18 @@ func (s *Provider) GetProvider(c fiber.Ctx) error {
|
|||||||
return c.JSON(web.NewResponse(provider))
|
return c.JSON(web.NewResponse(provider))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *Provider) FindSellers(c fiber.Ctx) error {
|
||||||
|
var query storage.ListProviderQuery
|
||||||
|
if err := c.Bind().Query(&query); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
providers, err := s.storage.Provider().Find(&query)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return c.JSON(web.NewResponse(providers))
|
||||||
|
}
|
||||||
|
|
||||||
func (s *Provider) DeleteProvider(c fiber.Ctx) error {
|
func (s *Provider) DeleteProvider(c fiber.Ctx) error {
|
||||||
sid := c.Params("id")
|
sid := c.Params("id")
|
||||||
if sid == "" {
|
if sid == "" {
|
||||||
@ -96,3 +112,34 @@ func (s *Provider) DeleteProvider(c fiber.Ctx) error {
|
|||||||
}
|
}
|
||||||
return c.JSON(web.NewResponse(provider))
|
return c.JSON(web.NewResponse(provider))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 返回状态字典
|
||||||
|
func (s *Provider) DictStatus(c fiber.Ctx) error {
|
||||||
|
dicts := []utils.Dict{
|
||||||
|
{
|
||||||
|
Key: "provider_status_normal",
|
||||||
|
Value: v2.ProviderStatus_Normal,
|
||||||
|
Title: "正常",
|
||||||
|
Color: "#87d068",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Key: "provider_status_pulling",
|
||||||
|
Value: v2.ProviderStatus_Pulling,
|
||||||
|
Title: "抓取中",
|
||||||
|
Color: "#108ee9",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Key: "provider_status_calculate",
|
||||||
|
Value: v2.ProviderStatus_Calculating,
|
||||||
|
Title: "计算中",
|
||||||
|
Color: "#108ee9",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Key: "provider_status_error",
|
||||||
|
Value: v2.ProviderStatus_Error,
|
||||||
|
Title: "出错",
|
||||||
|
Color: "red",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
return c.JSON(web.NewResponse(dicts))
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user