fix 修复coach-client接口问题
All checks were successful
Build image / build (push) Successful in 1m30s

This commit is contained in:
timerzz 2024-05-14 17:43:08 +08:00
parent 6d247632b7
commit 075a4812e4
4 changed files with 30 additions and 10 deletions

View File

@ -6,9 +6,9 @@ import (
"gitea.timerzz.com/kedaya_haitao/common/pkg/proxy" "gitea.timerzz.com/kedaya_haitao/common/pkg/proxy"
restry_pool "gitea.timerzz.com/kedaya_haitao/common/pkg/restry-pool" restry_pool "gitea.timerzz.com/kedaya_haitao/common/pkg/restry-pool"
"github.com/go-resty/resty/v2" "github.com/go-resty/resty/v2"
"github.com/golang/glog"
"github.com/pkg/errors" "github.com/pkg/errors"
proxy2 "github.com/timerzz/proxypool/pkg/proxy" proxy2 "github.com/timerzz/proxypool/pkg/proxy"
"log/slog"
"time" "time"
) )
@ -30,7 +30,7 @@ func (c *Client) ViewAllBags(ctx context.Context, page int) (resp PageDataRespon
} }
sctx, cancel := context.WithTimeout(ctx, c.defaultTimeOut) sctx, cancel := context.WithTimeout(ctx, c.defaultTimeOut)
defer cancel() defer cancel()
urlPath := fmt.Sprintf("https://www.coachoutlet.com/api/get-shop/bags/view-all?page=%s", page) urlPath := fmt.Sprintf("https://www.coachoutlet.com/api/get-shop/bags/view-all?page=%d", page)
err = tryRequest(sctx, urlPath, &resp, c.pool.RandomIterator()) err = tryRequest(sctx, urlPath, &resp, c.pool.RandomIterator())
return return
} }
@ -45,7 +45,7 @@ func tryRequest(ctx context.Context, urlPath string, respData any, proxyGetter f
} }
_, err := callByProxy(ctx, p, urlPath, respData) _, err := callByProxy(ctx, p, urlPath, respData)
if err != nil { if err != nil {
slog.Debug(err.Error()) glog.Error(err)
continue continue
} }
return nil return nil

View File

@ -0,0 +1,18 @@
package coach_client
import (
"context"
"gitea.timerzz.com/kedaya_haitao/common/pkg/proxy"
"testing"
)
func TestClient(t *testing.T) {
subs := []string{"https://us.timerzz.com:26106/vmess/sub", "https://us.timerzz.com:26106/trojan/sub", "https://us.timerzz.com:26106/ssr/sub"}
pool := proxy.NewProxyPool(subs)
client := NewClient(pool)
resp, err := client.ViewAllBags(context.Background(), 1)
if err != nil {
t.Fatal(err)
}
t.Log(resp)
}

View File

@ -1,11 +1,13 @@
package coach_client package coach_client
type PageDataResponse struct { type PageDataResponse struct {
Total int `json:"total"` PageData struct {
Page int `json:"page"` Total int `json:"total"`
TotalPages int `json:"totalPages"` Page int `json:"page"`
PageSize int `json:"pageSize"` TotalPages int `json:"totalPages"`
Products []Product `json:"products"` PageSize int `json:"pageSize"`
Products []Product `json:"products"`
} `json:"pageData"`
} }
type Product struct { type Product struct {
Name string `json:"name"` Name string `json:"name"`

View File

@ -67,9 +67,9 @@ func (c *Controller) Crawl() error {
if err != nil { if err != nil {
return fmt.Errorf("访问coach第%d页失败: %w", page, err) return fmt.Errorf("访问coach第%d页失败: %w", page, err)
} }
totalPage = resp.TotalPages totalPage = resp.PageData.TotalPages
if err = c.saveRespData(resp.Products); err != nil { if err = c.saveRespData(resp.PageData.Products); err != nil {
return fmt.Errorf("保存第%d页数据失败: %w", page, err) return fmt.Errorf("保存第%d页数据失败: %w", page, err)
} }
} }