ADD 获取供应商是否在线
All checks were successful
Build image / build (push) Successful in 59s

This commit is contained in:
timerzz 2025-03-27 17:51:06 +08:00
parent ee9fab7a8f
commit 1ee66cc8f5
3 changed files with 22 additions and 5 deletions

2
go.mod
View File

@ -5,7 +5,7 @@ go 1.23.0
toolchain go1.23.7
require (
gitea.timerzz.com/kedaya_haitao/common v0.0.0-20250327021208-7303e49bd09a
gitea.timerzz.com/kedaya_haitao/common v0.0.0-20250327094730-83e8af0c5f4b
github.com/gofiber/fiber/v3 v3.0.0-beta.4
github.com/henrylee2cn/ameda v1.4.10
github.com/redis/go-redis/v9 v9.6.1

4
go.sum
View File

@ -1,5 +1,5 @@
gitea.timerzz.com/kedaya_haitao/common v0.0.0-20250327021208-7303e49bd09a h1:AIi74nG73laj16WMoXAbMDyNCZoHt9vdWtCeEp/wybo=
gitea.timerzz.com/kedaya_haitao/common v0.0.0-20250327021208-7303e49bd09a/go.mod h1:cfkwyDHbOjucM8xLLg8yIkZKz33kdVqvBZYrfNjM8oc=
gitea.timerzz.com/kedaya_haitao/common v0.0.0-20250327094730-83e8af0c5f4b h1:nrEcJvWPWlVezQZ1eQAbpgOLieDmqVt2zkmTQci1iwo=
gitea.timerzz.com/kedaya_haitao/common v0.0.0-20250327094730-83e8af0c5f4b/go.mod h1:cfkwyDHbOjucM8xLLg8yIkZKz33kdVqvBZYrfNjM8oc=
github.com/andybalholm/brotli v1.1.1 h1:PR2pgnyFznKEugtsUo0xLdDop5SKXd5Qf5ysW+7XdTA=
github.com/andybalholm/brotli v1.1.1/go.mod h1:05ib4cKhjx3OQYUY22hTVd34Bc8upXjOLL2rKwwZBoA=
github.com/bsm/ginkgo/v2 v2.12.0 h1:Ny8MWAHyOepLGlLKYmXG4IEkioBysk6GpaRTLC8zwWs=

View File

@ -1,12 +1,18 @@
package service
import (
"fmt"
"net/http"
"sync"
"time"
"gitea.timerzz.com/kedaya_haitao/common/pkg/subscribe"
"gitea.timerzz.com/kedaya_haitao/common/pkg/web"
"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"
"github.com/gofiber/fiber/v3"
"github.com/gofiber/fiber/v3/client"
"github.com/henrylee2cn/ameda"
"github.com/redis/go-redis/v9"
"github.com/sirupsen/logrus"
@ -46,7 +52,19 @@ func (s *Provider) ListProviders(c fiber.Ctx) error {
if err != nil {
return err
}
var wg sync.WaitGroup
for idx := range providers {
wg.Add(1)
go func(idx int) {
defer wg.Done()
p := providers[idx]
resp, _ := client.C().Get(fmt.Sprintf("http://%s/living", p.ProviderId), client.Config{Timeout: time.Second})
if resp != nil && resp.StatusCode() == http.StatusOK {
providers[idx].Online = true
}
}(idx)
}
wg.Wait()
return c.JSON(web.NewResponse(web.NewListResponse(total, providers)))
}
@ -85,7 +103,6 @@ func (s *Provider) GetProvider(c fiber.Ctx) error {
return fiber.ErrBadRequest
}
provider, err := s.storage.Provider().Get(uint(id))
if err != nil {
return err
}