update 添加RequestProductDetailList方法,用于批量获取商品信息
This commit is contained in:
parent
89a406d32f
commit
44514fbf39
@ -5,6 +5,7 @@ import (
|
||||
"fmt"
|
||||
"net/url"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"gitea.timerzz.com/kedaya_haitao/common/pkg/proxy"
|
||||
@ -98,6 +99,20 @@ func (c *ca) RequestProductDetail(ctx context.Context, pid string) (data Product
|
||||
return
|
||||
}
|
||||
|
||||
func (c *ca) RequestProductDetailList(ctx context.Context, pids ...string) (list []*ProductData, err error) {
|
||||
sctx, cancel := context.WithTimeout(ctx, c.defaultTimeOut)
|
||||
defer cancel()
|
||||
var resp ProductDataResponse
|
||||
var ids = strings.Join(pids, ",")
|
||||
urlPath := fmt.Sprintf("/api/get-products?ids=%s&includeInventory=false", url.QueryEscape(ids))
|
||||
err = tryRequest(sctx, c.baseUrl, urlPath, &resp, c.pool.RandomIterator())
|
||||
if len(resp.ProductData) == 0 && err != nil {
|
||||
err = fmt.Errorf("获取详情信息为空")
|
||||
return
|
||||
}
|
||||
return resp.ProductData, nil
|
||||
}
|
||||
|
||||
func (c *ca) ViewAllBags(ctx context.Context, page int) (resp PageDataResponse, err error) {
|
||||
if page < 1 {
|
||||
page = 1
|
||||
|
@ -22,9 +22,9 @@ func TestCAClient(t *testing.T) {
|
||||
//}
|
||||
//t.Log(resp)
|
||||
|
||||
inv, err := client.RequestProductDetail(ctx, "CP150-LHBLK")
|
||||
resp, err := client.RequestProductDetailList(ctx, "CK535-WEC", "CP081-SVVSW", "C9949-SVVDT", "CM235-SVELC", "CP081-JIBLK", "CAA92-IMCHR", "C9949-SVQVE", "CW637-B4CED")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Log(inv)
|
||||
t.Log(resp)
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import (
|
||||
"fmt"
|
||||
"net/url"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"gitea.timerzz.com/kedaya_haitao/common/pkg/proxy"
|
||||
@ -108,6 +109,7 @@ func (u *USClientBuilder) CreateByType(clientType string) USCAClient {
|
||||
type USCAClient interface {
|
||||
RequestInventory(ctx context.Context, pid string) (inv Inventory, err error)
|
||||
RequestProductDetail(ctx context.Context, pid string) (data ProductData, err error)
|
||||
RequestProductDetailList(ctx context.Context, pids ...string) (list []*ProductData, err error)
|
||||
ViewAllBags(ctx context.Context, page int) (resp PageDataResponse, err error)
|
||||
BaseUrl() string
|
||||
}
|
||||
@ -236,6 +238,20 @@ func (c *us) RequestProductDetail(ctx context.Context, pid string) (data Product
|
||||
return
|
||||
}
|
||||
|
||||
func (c *us) RequestProductDetailList(ctx context.Context, pids ...string) (list []*ProductData, err error) {
|
||||
sctx, cancel := context.WithTimeout(ctx, c.defaultTimeOut)
|
||||
defer cancel()
|
||||
var resp ProductDataResponse
|
||||
var ids = strings.Join(pids, ",")
|
||||
urlPath := fmt.Sprintf("/api/get-products?ids=%s&includeInventory=false", url.QueryEscape(ids))
|
||||
err = tryRequest(sctx, c.baseUrl, urlPath, &resp, c.pool.RandomIterator())
|
||||
if len(resp.ProductData) == 0 && err != nil {
|
||||
err = fmt.Errorf("获取详情信息为空")
|
||||
return
|
||||
}
|
||||
return resp.ProductData, nil
|
||||
}
|
||||
|
||||
type PageDataResponse struct {
|
||||
PageData struct {
|
||||
Total int `json:"total"`
|
||||
|
@ -15,7 +15,7 @@ func TestClient(t *testing.T) {
|
||||
Interval: 10 * time.Minute,
|
||||
})
|
||||
client := US(pool).CreateByType(USClient_Type_Coach)
|
||||
resp, err := client.ViewAllBags(context.Background(), 1)
|
||||
resp, err := client.RequestProductDetailList(context.Background(), "CK535-WEC", "CP081-SVVSW", "C9949-SVVDT", "CM235-SVELC", "CP081-JIBLK", "CAA92-IMCHR", "C9949-SVQVE", "CW637-B4CED")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user