Documentation ¶
Index ¶
- Variables
- type HTTPClientBuilder
- func (b *HTTPClientBuilder) AddMockedDomain(domain string) *HTTPClientBuilder
- func (b *HTTPClientBuilder) Build(replaceDefault ...bool) (*http.Client, error)
- func (b *HTTPClientBuilder) FromConfig(config *config.HTTPClientConfig) *HTTPClientBuilder
- func (b *HTTPClientBuilder) ReplaceDefault() *HTTPClientBuilder
- func (b *HTTPClientBuilder) RestoreDefault() *HTTPClientBuilder
- func (b *HTTPClientBuilder) SetCertPool(pool *x509.CertPool) *HTTPClientBuilder
- func (b *HTTPClientBuilder) SetLogging(flag bool) *HTTPClientBuilder
- func (b *HTTPClientBuilder) SetMockAddress(address string) *HTTPClientBuilder
- func (b *HTTPClientBuilder) SetMockedDomains(domains []string) *HTTPClientBuilder
- func (b *HTTPClientBuilder) SetProxy(proxy func(*http.Request) (*url.URL, error)) *HTTPClientBuilder
- func (b *HTTPClientBuilder) SetSSLVerification(enabled bool) *HTTPClientBuilder
- func (b *HTTPClientBuilder) SetTimeout(seconds time.Duration) *HTTPClientBuilder
- func (b *HTTPClientBuilder) UseTLS10() *HTTPClientBuilder
- func (b *HTTPClientBuilder) WithLogger(logger logger.Logger) *HTTPClientBuilder
Constants ¶
This section is empty.
Variables ¶
var DefaultClient = http.DefaultClient
DefaultClient stores original http.DefaultClient.
var DefaultTransport = http.DefaultTransport
DefaultTransport stores original http.DefaultTransport.
Functions ¶
This section is empty.
Types ¶
type HTTPClientBuilder ¶
type HTTPClientBuilder struct {
// contains filtered or unexported fields
}
HTTPClientBuilder builds http client with mocks (if necessary) and timeout. Example:
// Build HTTP client with timeout = 10 sec, without SSL certificates verification and with mocked google.com client, err := NewHTTPClientBuilder(). SetTimeout(10). SetMockAddress("api_mock:3004"). AddMockedDomain("google.com"). SetSSLVerification(false). Build() if err != nil { fmt.Print(err) } // Actual response will be returned from "api_mock:3004" (it should provide any ssl certificate) if resp, err := client.Get("https://google.com"); err == nil { if data, err := ioutil.ReadAll(resp.Body); err == nil { fmt.Printf("Data: %s", string(data)) } else { fmt.Print(err) } } else { fmt.Print(err) }
func NewHTTPClientBuilder ¶
func NewHTTPClientBuilder() *HTTPClientBuilder
NewHTTPClientBuilder returns HTTPClientBuilder with default values.
func (*HTTPClientBuilder) AddMockedDomain ¶
func (b *HTTPClientBuilder) AddMockedDomain(domain string) *HTTPClientBuilder
AddMockedDomain adds new mocked domain.
func (*HTTPClientBuilder) Build ¶
func (b *HTTPClientBuilder) Build(replaceDefault ...bool) (*http.Client, error)
Build builds client, pass true to replace http.DefaultClient with generated one.
func (*HTTPClientBuilder) FromConfig ¶
func (b *HTTPClientBuilder) FromConfig(config *config.HTTPClientConfig) *HTTPClientBuilder
FromConfig fulfills mock configuration from HTTPClientConfig.
func (*HTTPClientBuilder) ReplaceDefault ¶
func (b *HTTPClientBuilder) ReplaceDefault() *HTTPClientBuilder
ReplaceDefault replaces default client and transport with generated ones.
func (*HTTPClientBuilder) RestoreDefault ¶
func (b *HTTPClientBuilder) RestoreDefault() *HTTPClientBuilder
RestoreDefault restores default client and transport after replacement.
func (*HTTPClientBuilder) SetCertPool ¶
func (b *HTTPClientBuilder) SetCertPool(pool *x509.CertPool) *HTTPClientBuilder
SetCertPool sets provided TLS certificates pool into the client.
func (*HTTPClientBuilder) SetLogging ¶
func (b *HTTPClientBuilder) SetLogging(flag bool) *HTTPClientBuilder
SetLogging enables or disables logging in mocks.
func (*HTTPClientBuilder) SetMockAddress ¶
func (b *HTTPClientBuilder) SetMockAddress(address string) *HTTPClientBuilder
SetMockAddress sets mock address.
func (*HTTPClientBuilder) SetMockedDomains ¶
func (b *HTTPClientBuilder) SetMockedDomains(domains []string) *HTTPClientBuilder
SetMockedDomains sets mocked domains from slice.
func (*HTTPClientBuilder) SetProxy ¶ added in v2.7.5
func (b *HTTPClientBuilder) SetProxy(proxy func(*http.Request) (*url.URL, error)) *HTTPClientBuilder
func (*HTTPClientBuilder) SetSSLVerification ¶
func (b *HTTPClientBuilder) SetSSLVerification(enabled bool) *HTTPClientBuilder
SetSSLVerification enables or disables SSL certificates verification in client.
func (*HTTPClientBuilder) SetTimeout ¶
func (b *HTTPClientBuilder) SetTimeout(seconds time.Duration) *HTTPClientBuilder
SetTimeout sets timeout for http client.
func (*HTTPClientBuilder) UseTLS10 ¶
func (b *HTTPClientBuilder) UseTLS10() *HTTPClientBuilder
UseTLS10 restores TLS 1.0 as a minimal supported TLS version.
func (*HTTPClientBuilder) WithLogger ¶
func (b *HTTPClientBuilder) WithLogger(logger logger.Logger) *HTTPClientBuilder
WithLogger sets provided logger into HTTPClientBuilder.