From ee3f7ce41b28e3235d4890f58e994ab4cef37562 Mon Sep 17 00:00:00 2001 From: timerzz Date: Fri, 6 Dec 2024 17:19:19 +0800 Subject: [PATCH] =?UTF-8?q?feat=20=E6=B7=BB=E5=8A=A0coach=20=E5=AE=A2?= =?UTF-8?q?=E6=88=B7=E7=AB=AF=20=E5=8A=A0=E8=BD=BD=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/coach-client/us.go | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/pkg/coach-client/us.go b/pkg/coach-client/us.go index 9f9e76e..0a3c860 100644 --- a/pkg/coach-client/us.go +++ b/pkg/coach-client/us.go @@ -5,11 +5,13 @@ import ( "fmt" "log/slog" "net/url" + "os" "time" "gitea.timerzz.com/kedaya_haitao/common/pkg/proxy" restry_pool "gitea.timerzz.com/kedaya_haitao/common/pkg/restry-pool" "github.com/go-resty/resty/v2" + "github.com/golang/glog" "github.com/pkg/errors" proxy2 "github.com/timerzz/proxypool/pkg/proxy" ) @@ -19,6 +21,26 @@ const ( BaseUrl_CoachOutlet = "https://www.coachoutlet.com" ) +const ( + USClient_Type_Coach = "coach" + USClient_Type_Coach_Outlet = "coach_outlet" +) + +const ( + USClient_Type_Env_Key = "COACH_CLIENT_TYPE" +) + +func LoadUSClientType() string { + clientType := os.Getenv(USClient_Type_Env_Key) + if clientType == "" { + glog.Fatal("加载coach客户端类型失败") + } + if clientType != USClient_Type_Coach && clientType != USClient_Type_Coach_Outlet { + glog.Fatal("加载coach客户端类型不正确") + } + return clientType +} + type USClientBuilder struct { pool *proxy.ProxyPool } @@ -45,10 +67,20 @@ func (u *USClientBuilder) CoachOutlet() USClient { } } +func (u *USClientBuilder) CreateByType(clientType string) USClient { + if clientType == USClient_Type_Coach { + return u.Coach() + } else if clientType == USClient_Type_Coach_Outlet { + return u.CoachOutlet() + } + return nil +} + type USClient interface { RequestInventory(ctx context.Context, pid string) (inv Inventory, err error) RequestProductDetail(ctx context.Context, pid string) (data ProductData, err error) ViewAllBags(ctx context.Context, page int) (resp PageDataResponse, err error) + BaseUrl() string } type us struct { @@ -119,6 +151,10 @@ type InventoryResponse struct { } `json:"inventory"` } +func (c *us) BaseUrl() string { + return c.baseUrl +} + func (c *us) RequestInventory(ctx context.Context, pid string) (inv Inventory, err error) { sctx, cancel := context.WithTimeout(ctx, c.defaultTimeOut) defer cancel()