dw-sdk/client.go

65 lines
1.4 KiB
Go

package dw_sdk
import (
"fmt"
"os"
)
type Client struct {
articleServiceClient ArticleServiceClient
consignBidClient BidClient
preSaleBidClient BidClient
normalBidClient BidClient
}
func InitDefaultDWClient() (*Client, error) {
path := os.Getenv(ConfigPathEnvKey)
if path == "" {
path = DefaultConfigPath
}
cfg, err := LoadDWConfig(path)
if err != nil {
return nil, fmt.Errorf("获取得物配置失败:%v", err)
}
cli := NewClient(*cfg)
return cli, nil
}
func NewClient(cfg Config) *Client {
return &Client{
articleServiceClient: NewArticleServiceClient(cfg),
consignBidClient: NewConsignBidClient(cfg),
preSaleBidClient: NewPreSaleBidClient(cfg),
normalBidClient: NewNormalBidClient(cfg),
}
}
func (c *Client) BidClientByBidType(bidType BiddingType) BidClient {
switch bidType {
case BiddingType_Normal:
return c.normalBidClient
case BiddingType_PreSale, BiddingType_Fast_PreSale:
return c.preSaleBidClient
case BiddingType_Consign:
return c.consignBidClient
default:
return nil
}
}
func (c *Client) ArticleService() ArticleServiceClient {
return c.articleServiceClient
}
func (c *Client) ConsignBidClient() BidClient {
return c.consignBidClient
}
func (c *Client) PreSaleBidClient() BidClient {
return c.preSaleBidClient
}
func (c *Client) NormalBidClient() BidClient {
return c.normalBidClient
}