feat 添加coach 客户端 加载方法

This commit is contained in:
timerzz 2024-12-06 17:19:19 +08:00
parent ea5315348b
commit ee3f7ce41b

View File

@ -5,11 +5,13 @@ import (
"fmt" "fmt"
"log/slog" "log/slog"
"net/url" "net/url"
"os"
"time" "time"
"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"
) )
@ -19,6 +21,26 @@ const (
BaseUrl_CoachOutlet = "https://www.coachoutlet.com" 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 { type USClientBuilder struct {
pool *proxy.ProxyPool 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 { type USClient interface {
RequestInventory(ctx context.Context, pid string) (inv Inventory, err error) RequestInventory(ctx context.Context, pid string) (inv Inventory, err error)
RequestProductDetail(ctx context.Context, pid string) (data ProductData, err error) RequestProductDetail(ctx context.Context, pid string) (data ProductData, err error)
ViewAllBags(ctx context.Context, page int) (resp PageDataResponse, err error) ViewAllBags(ctx context.Context, page int) (resp PageDataResponse, err error)
BaseUrl() string
} }
type us struct { type us struct {
@ -119,6 +151,10 @@ type InventoryResponse struct {
} `json:"inventory"` } `json:"inventory"`
} }
func (c *us) BaseUrl() string {
return c.baseUrl
}
func (c *us) RequestInventory(ctx context.Context, pid string) (inv Inventory, err error) { func (c *us) RequestInventory(ctx context.Context, pid string) (inv Inventory, err error) {
sctx, cancel := context.WithTimeout(ctx, c.defaultTimeOut) sctx, cancel := context.WithTimeout(ctx, c.defaultTimeOut)
defer cancel() defer cancel()