We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sometimes we need to use custom Transport or set Timeout.
The text was updated successfully, but these errors were encountered:
@choleraehyq do you have more concret example?
Sorry, something went wrong.
For example instead of:
type MarketClient struct { publicUrlBuilder *requestbuilder.PublicUrlBuilder } // Initializer func (p *MarketClient) Init(host string) *MarketClient { p.publicUrlBuilder = new(requestbuilder.PublicUrlBuilder).Init(host) return p }
Use pattern 'Constructor' and pass HTTP client as interface argument:
type Requestor interface{ Get(string) ([]byte, error) Post(string, map[string]string) ([]byte, error) } type MarketClient struct { publicUrlBuilder *requestbuilder.PublicUrlBuilder client Requestor } func NewMarket(host string, cli Requestor) *MarketClient { p.publicUrlBuilder = new(requestbuilder.PublicUrlBuilder).Init(host) p.client = cli return p } func (mc *MarketClient) GetLatestTrade(symbol string) (*market.TradeTick, error) { request := new(model.GetRequest).Init() request.AddParam("symbol", symbol) url := mc.publicUrlBuilder.Build("/market/trade", request) resp, err := mc.cli.Get(url) if err != nil { return nil, err } result := market.GetLatestTradeResponse{} err = json.Unmarshal(resp, &result) if err != nil { return nil, err } if result.Status == "ok" && result.Tick != nil { return result.Tick, nil } return nil, errors.New(resp) }
No branches or pull requests
Sometimes we need to use custom Transport or set Timeout.
The text was updated successfully, but these errors were encountered: