Documentation
¶
Overview ¶
Package web contains HTTP request and client configurations. HTTP structure embeds both of them, and it's the only structure that intended to be used as part of a module's configuration. Every module that uses HTTP requests to collect metrics should use it. It allows to have same set of user configurable options across all modules.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ErrRedirectAttempted = errors.New("redirect")
ErrRedirectAttempted indicates that a redirect occurred.
Functions ¶
func NewHTTPClient ¶
NewHTTPClient returns a new *http.Client given a Client configuration and an error if any.
Types ¶
type Client ¶
type Client struct {
// Timeout specifies a time limit for requests made by this Client.
// Default (zero value) is no timeout. Must be set before http.Client creation.
Timeout Duration `yaml:"timeout"`
// NotFollowRedirect specifies the policy for handling redirects.
// Default (zero value) is std http package default policy (stop after 10 consecutive requests).
NotFollowRedirect bool `yaml:"not_follow_redirects"`
// ProxyURL specifies the URL of the proxy to use. An empty string means use the environment variables
// HTTP_PROXY, HTTPS_PROXY and NO_PROXY (or the lowercase versions thereof) to get the URL.
ProxyURL string `yaml:"proxy_url"`
// TLSConfig specifies the TLS configuration.
tlscfg.TLSConfig `yaml:",inline"`
}
Client is the configuration of the HTTP client. This structure is not intended to be used directly as part of a module's configuration. Supported configuration file formats: YAML.
type Duration ¶
Duration is a time.Duration wrapper.
func (*Duration) UnmarshalYAML ¶
UnmarshalYAML implements yaml.Unmarshaler.
type HTTP ¶
HTTP is a struct with embedded Request and Client. This structure intended to be part of the module configuration. Supported configuration file formats: YAML.
Example (Usage) ¶
// Just embed HTTP into your module structure.
// It allows you to have both Request and Client fields in the module configuration file.
type myModule struct {
HTTP `yaml:",inline"`
}
var m myModule
_, _ = NewHTTPRequest(m.Request)
_, _ = NewHTTPClient(m.Client)
type Request ¶
type Request struct {
// URL specifies the URL to access.
URL string `yaml:"url"`
// Body specifies the HTTP request body to be sent by the client.
Body string `yaml:"body"`
// Method specifies the HTTP method (GET, POST, PUT, etc.). An empty string means GET.
Method string `yaml:"method"`
// Headers specifies the HTTP request header fields to be sent by the client.
Headers map[string]string `yaml:"headers"`
// Username specifies the username for basic HTTP authentication.
Username string `yaml:"username"`
// Password specifies the password for basic HTTP authentication.
Password string `yaml:"password"`
// ProxyUsername specifies the username for basic HTTP authentication.
// It is used to authenticate a user agent to a proxy server.
ProxyUsername string `yaml:"proxy_username"`
// ProxyPassword specifies the password for basic HTTP authentication.
// It is used to authenticate a user agent to a proxy server.
ProxyPassword string `yaml:"proxy_password"`
}
Request is the configuration of the HTTP request. This structure is not intended to be used directly as part of a module's configuration. Supported configuration file formats: YAML.