Documentation
¶
Overview ¶
Package estransport provides the transport layer for the Elasticsearch client.
It is automatically included in the client provided by the github.com/elastic/go-elasticsearch package and is not intended for direct use: to configure the client, use the elasticsearch.Config struct.
The default HTTP transport of the client is http.Transport.
The package defines the "Selector" interface for getting a URL from the list. At the moment, the implementation is rather minimal: the client takes a slice of url.URL pointers, and round-robins across them when performing the request.
The package defines the "Logger" interface for logging information about request and response. It comes with several bundled loggers for logging in text and JSON.
Index ¶
Constants ¶
const Version = version.Client
Version returns the package version as a string.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client represents the HTTP client.
func New ¶
New creates new HTTP client.
http.DefaultTransport will be used if no transport is passed in the configuration.
type ColorLogger ¶
ColorLogger prints the log message in a terminal-optimized plain text.
func (*ColorLogger) LogRoundTrip ¶
func (l *ColorLogger) LogRoundTrip(req *http.Request, res *http.Response, err error, start time.Time, dur time.Duration) error
LogRoundTrip prints the information about request and response.
func (*ColorLogger) RequestBodyEnabled ¶
func (l *ColorLogger) RequestBodyEnabled() bool
RequestBodyEnabled returns true when the request body should be logged.
func (*ColorLogger) ResponseBodyEnabled ¶
func (l *ColorLogger) ResponseBodyEnabled() bool
ResponseBodyEnabled returns true when the response body should be logged.
type Config ¶
type Config struct { URLs []*url.URL Username string Password string Transport http.RoundTripper Logger Logger }
Config represents the configuration of HTTP client.
type CurlLogger ¶
CurlLogger prints the log message as a runnable curl command.
func (*CurlLogger) LogRoundTrip ¶
func (l *CurlLogger) LogRoundTrip(req *http.Request, res *http.Response, err error, start time.Time, dur time.Duration) error
LogRoundTrip prints the information about request and response.
func (*CurlLogger) RequestBodyEnabled ¶
func (l *CurlLogger) RequestBodyEnabled() bool
RequestBodyEnabled returns true when the request body should be logged.
func (*CurlLogger) ResponseBodyEnabled ¶
func (l *CurlLogger) ResponseBodyEnabled() bool
ResponseBodyEnabled returns true when the response body should be logged.
type JSONLogger ¶
JSONLogger prints the log message as JSON.
func (*JSONLogger) LogRoundTrip ¶
func (l *JSONLogger) LogRoundTrip(req *http.Request, res *http.Response, err error, start time.Time, dur time.Duration) error
LogRoundTrip prints the information about request and response.
func (*JSONLogger) RequestBodyEnabled ¶
func (l *JSONLogger) RequestBodyEnabled() bool
RequestBodyEnabled returns true when the request body should be logged.
func (*JSONLogger) ResponseBodyEnabled ¶
func (l *JSONLogger) ResponseBodyEnabled() bool
ResponseBodyEnabled returns true when the response body should be logged.
type Logger ¶
type Logger interface { // LogRoundTrip should not modify the request or response, except for consuming and closing the body. // Implementations have to check for nil values in request and response. LogRoundTrip(*http.Request, *http.Response, error, time.Time, time.Duration) error // RequestBodyEnabled makes the client pass a copy of request body to the logger. RequestBodyEnabled() bool // ResponseBodyEnabled makes the client pass a copy of response body to the logger. ResponseBodyEnabled() bool }
Logger defines an interface for logging request and response.
type RoundRobinSelector ¶
RoundRobinSelector implements a round-robin selection strategy.
func NewRoundRobinSelector ¶
func NewRoundRobinSelector(urls ...*url.URL) *RoundRobinSelector
NewRoundRobinSelector creates a new RoundRobinSelector.
type TextLogger ¶
TextLogger prints the log message in plain text.
func (*TextLogger) LogRoundTrip ¶
func (l *TextLogger) LogRoundTrip(req *http.Request, res *http.Response, err error, start time.Time, dur time.Duration) error
LogRoundTrip prints the information about request and response.
func (*TextLogger) RequestBodyEnabled ¶
func (l *TextLogger) RequestBodyEnabled() bool
RequestBodyEnabled returns true when the request body should be logged.
func (*TextLogger) ResponseBodyEnabled ¶
func (l *TextLogger) ResponseBodyEnabled() bool
ResponseBodyEnabled returns true when the response body should be logged.