package coach_client import ( "context" "fmt" "net/url" ) type ProductData struct { Id string `json:"id"` Name string `json:"name"` Brand string `json:"brand"` Inventory Inventory `json:"inventory"` Url string `json:"url"` MasterId string `json:"masterId"` Prices struct { CurrentPrice float64 `json:"currentPrice"` } `json:"prices"` Remark string `json:"-"` } type ProductDataResponse struct { ProductData []*ProductData `json:"productsData"` } func (c *Client) RequestProductDetail(ctx context.Context, pid string) (data ProductData, err error) { sctx, cancel := context.WithTimeout(ctx, c.defaultTimeOut) defer cancel() var resp ProductDataResponse urlPath := fmt.Sprintf("https://www.coachoutlet.com/api/get-products?ids=%s&includeInventory=false", url.QueryEscape(pid)) err = tryRequest(sctx, urlPath, &resp, c.pool.RandomIterator()) if len(resp.ProductData) == 0 && err != nil { err = fmt.Errorf("获取详情信息为空") return } if len(resp.ProductData) > 0 { data = *resp.ProductData[0] } return }