feat 使用SetDial设置代理
This commit is contained in:
parent
62b04c9599
commit
bee41b8bc4
@ -2,10 +2,12 @@ package dw_sdk
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/bytedance/sonic"
|
"github.com/bytedance/sonic"
|
||||||
"github.com/gofiber/fiber/v3/client"
|
"github.com/gofiber/fiber/v3/client"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"time"
|
"github.com/valyala/fasthttp/fasthttpproxy"
|
||||||
)
|
)
|
||||||
|
|
||||||
//商品服务API
|
//商品服务API
|
||||||
@ -27,10 +29,7 @@ func NewArticleServiceClient(cfg Config) ArticleServiceClient {
|
|||||||
return sonic.Unmarshal(data, v)
|
return sonic.Unmarshal(data, v)
|
||||||
}).SetBaseURL(GetUrl(cfg.Public.Env)).Debug()
|
}).SetBaseURL(GetUrl(cfg.Public.Env)).Debug()
|
||||||
if cfg.Proxy != nil {
|
if cfg.Proxy != nil {
|
||||||
err := cli.SetProxyURL(fmt.Sprintf("http://%s:%s@%s:%s", cfg.Proxy.User, cfg.Proxy.Pass, cfg.Proxy.Host, cfg.Proxy.Port))
|
cli.SetDial(fasthttpproxy.FasthttpHTTPDialer(fmt.Sprintf("%s:%s@%s:%s", cfg.Proxy.User, cfg.Proxy.Pass, cfg.Proxy.Host, cfg.Proxy.Port)))
|
||||||
if err != nil {
|
|
||||||
fmt.Println(err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return &ArticleServiceClientImpl{
|
return &ArticleServiceClientImpl{
|
||||||
cli: cli,
|
cli: cli,
|
||||||
|
@ -21,7 +21,7 @@ func TestNewArticleServiceClient(t *testing.T) {
|
|||||||
Pass: "zhhg1997",
|
Pass: "zhhg1997",
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
resp, err := cli.BatchArticleNumber([]string{"cq067"})
|
resp, err := cli.BatchArticleNumber([]string{"C4250-IMNLJ"})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
@ -2,9 +2,12 @@ package dw_sdk
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/bytedance/sonic"
|
"github.com/bytedance/sonic"
|
||||||
"github.com/gofiber/fiber/v3/client"
|
"github.com/gofiber/fiber/v3/client"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
|
"github.com/valyala/fasthttp/fasthttpproxy"
|
||||||
|
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -32,7 +35,7 @@ func NewConsignBidClient(cfg Config) BidClient {
|
|||||||
})
|
})
|
||||||
|
|
||||||
if cfg.Proxy != nil {
|
if cfg.Proxy != nil {
|
||||||
_ = cli.SetProxyURL(fmt.Sprintf("http://%s:%s@%s:%s", cfg.Proxy.User, cfg.Proxy.Pass, cfg.Proxy.Host, cfg.Proxy.Port))
|
cli.SetDial(fasthttpproxy.FasthttpHTTPDialer(fmt.Sprintf("%s:%s@%s:%s", cfg.Proxy.User, cfg.Proxy.Pass, cfg.Proxy.Host, cfg.Proxy.Port)))
|
||||||
}
|
}
|
||||||
return &ConsignBidClientImpl{
|
return &ConsignBidClientImpl{
|
||||||
cli: cli,
|
cli: cli,
|
||||||
|
@ -12,8 +12,20 @@ var testConfig = Config{
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestNewBidConsignClient(t *testing.T) {
|
func TestNewBidConsignClient(t *testing.T) {
|
||||||
cli := NewConsignBidClient(testConfig)
|
cli := NewConsignBidClient(Config{
|
||||||
resp, err := cli.LowestPrice(123)
|
Public: PublicConfig{
|
||||||
|
Key: "92a2afa02627410fae9e3331cc850224",
|
||||||
|
Secret: "73b5bf12bc5e4b4690f444b32b934dc0feb1e42977514333a76f263592ee37f4",
|
||||||
|
Env: "online",
|
||||||
|
},
|
||||||
|
Proxy: &ProxyConfig{
|
||||||
|
Host: "jd.timerzz.com",
|
||||||
|
Port: "8090",
|
||||||
|
User: "timerzz",
|
||||||
|
Pass: "zhhg1997",
|
||||||
|
},
|
||||||
|
})
|
||||||
|
resp, err := cli.LowestPrice(626512954)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user