estransport

package
v7.3.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 1, 2019 License: Apache-2.0 Imports: 17 Imported by: 0

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

View Source
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

func New(cfg Config) *Client

New creates new HTTP client.

http.DefaultTransport will be used if no transport is passed in the configuration.

func (*Client) Perform

func (c *Client) Perform(req *http.Request) (*http.Response, error)

Perform executes the request and returns a response or error.

func (*Client) URLs

func (c *Client) URLs() []*url.URL

URLs returns a list of transport URLs.

type ColorLogger

type ColorLogger struct {
	Output             io.Writer
	EnableRequestBody  bool
	EnableResponseBody bool
}

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
	APIKey   string

	Transport http.RoundTripper
	Logger    Logger
}

Config represents the configuration of HTTP client.

type CurlLogger

type CurlLogger struct {
	Output             io.Writer
	EnableRequestBody  bool
	EnableResponseBody bool
}

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 Interface

type Interface interface {
	Perform(*http.Request) (*http.Response, error)
}

Interface defines the interface for HTTP client.

type JSONLogger

type JSONLogger struct {
	Output             io.Writer
	EnableRequestBody  bool
	EnableResponseBody bool
}

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

type RoundRobinSelector struct {
	sync.Mutex
	// contains filtered or unexported fields
}

RoundRobinSelector implements a round-robin selection strategy.

func NewRoundRobinSelector

func NewRoundRobinSelector(urls ...*url.URL) *RoundRobinSelector

NewRoundRobinSelector creates a new RoundRobinSelector.

func (*RoundRobinSelector) Select

func (r *RoundRobinSelector) Select() (*url.URL, error)

Select returns a URL or error from the list of URLs in a round-robin fashion.

type Selector

type Selector interface {
	Select() (*url.URL, error)
}

Selector defines the interface for selecting URLs for performing request.

type TextLogger

type TextLogger struct {
	Output             io.Writer
	EnableRequestBody  bool
	EnableResponseBody bool
}

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL