Exemplo n.º 1
0
// New returns a new *Client. The ctx parameter will usually be
// the *app.Context received by the handler which is calling this
// function. Note that passing a nil ctx will work under some circunstances
// but will fail when running on App Engine, so it's advisable to always
// pass an *app.Context to this function, for portability.
func New(ctx Context) *Client {
	tr := newTransport(ctx)
	client := &Client{
		transport: tr,
		c:         &http.Client{Transport: tr},
	}
	client.SetUserAgent(DefaultUserAgent)
	client.SetTimeout(DefaultTimeout)
	if log, ok := ctx.(logger); ok {
		client.logger = log.Logger()
	}
	return client
}
Exemplo n.º 2
0
func (c *Client) Clone(ctx Context) *Client {
	if c == nil || c.transport == nil {
		return New(ctx)
	}
	tr := c.transport.clone(ctx)
	cp := &Client{
		transport: tr,
		c:         &http.Client{Transport: tr},
	}
	if proxy := c.Proxy(); proxy != nil {
		cp.SetProxy(proxy)
	}
	if log, ok := ctx.(logger); ok {
		cp.logger = log.Logger()
	} else {
		cp.logger = nil
	}
	return cp
}