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()