http

package
v2.5.4 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2021 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package http provides HTTP servicing related code.

Important type is Service which handles HTTP operations. It is internally used by library and it is not necessary to use it directly for common operations. It can be useful when creating custom InfluxDB2 server API calls using generated code from the domain package, that are not yet exposed by API of this library.

Service can be obtained from client using HTTPService() method. It can be also created directly. To instantiate a Service use NewService(). Remember, the authorization param is in form "Token your-auth-token". e.g. "Token DXnd7annkGteV5Wqx9G3YjO9Ezkw87nHk8OabcyHCxF5451kdBV0Ag2cG7OmZZgCUTHroagUPdxbuoyen6TSPw==".

srv := http.NewService("http://localhost:8086", "Token my-token", http.DefaultOptions())

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Doer

type Doer interface {
	Do(*http.Request) (*http.Response, error)
}

Doer allows proving custom Do for HTTP operations

type Error

type Error struct {
	StatusCode int
	Code       string
	Message    string
	Err        error
	RetryAfter uint
}

Error represent error response from InfluxDBServer or http error

func NewError

func NewError(err error) *Error

NewError returns newly created Error initialised with nested error and default values

func (*Error) Error

func (e *Error) Error() string

Error fulfils error interface

func (*Error) Unwrap

func (e *Error) Unwrap() error

type Options

type Options struct {
	// contains filtered or unexported fields
}

Options holds http configuration properties for communicating with InfluxDB server

func DefaultOptions

func DefaultOptions() *Options

DefaultOptions returns Options object with default values

func (*Options) HTTPClient

func (o *Options) HTTPClient() *http.Client

HTTPClient returns the http.Client that is configured to be used for HTTP requests. It will return the one that has been set using SetHTTPClient or it will construct a default client using the other configured options. HTTPClient panics if SetHTTPDoer was called.

func (*Options) HTTPDoer

func (o *Options) HTTPDoer() Doer

HTTPDoer returns actual Doer if set, or http.Client

func (*Options) HTTPRequestTimeout

func (o *Options) HTTPRequestTimeout() uint

HTTPRequestTimeout returns HTTP request timeout

func (*Options) OwnHTTPClient

func (o *Options) OwnHTTPClient() bool

OwnHTTPClient returns true of HTTP client was created internally. False if it was set externally.

func (*Options) SetHTTPClient

func (o *Options) SetHTTPClient(c *http.Client) *Options

SetHTTPClient will configure the http.Client that is used for HTTP requests. If set to nil, an HTTPClient will be generated.

Setting the HTTPClient will cause the other HTTP options to be ignored. In case of UsersAPI.SignIn() is used, HTTPClient.Jar will be used for storing session cookie.

func (*Options) SetHTTPDoer

func (o *Options) SetHTTPDoer(d Doer) *Options

SetHTTPDoer will configure the http.Client that is used for HTTP requests. If set to nil, this has no effect.

Setting the HTTPDoer will cause the other HTTP options to be ignored.

func (*Options) SetHTTPRequestTimeout

func (o *Options) SetHTTPRequestTimeout(httpRequestTimeout uint) *Options

SetHTTPRequestTimeout sets HTTP request timeout in sec

func (*Options) SetTLSConfig

func (o *Options) SetTLSConfig(tlsConfig *tls.Config) *Options

SetTLSConfig sets TLS configuration for secure connection

func (*Options) TLSConfig

func (o *Options) TLSConfig() *tls.Config

TLSConfig returns tls.Config

type RequestCallback

type RequestCallback func(req *http.Request)

RequestCallback defines function called after a request is created before any call

type ResponseCallback

type ResponseCallback func(resp *http.Response) error

ResponseCallback defines function called after a successful response was received

type Service

type Service interface {
	// DoPostRequest sends HTTP POST request to the given url with body
	DoPostRequest(ctx context.Context, url string, body io.Reader, requestCallback RequestCallback, responseCallback ResponseCallback) *Error
	// DoHTTPRequest sends given HTTP request and handles response
	DoHTTPRequest(req *http.Request, requestCallback RequestCallback, responseCallback ResponseCallback) *Error
	// DoHTTPRequestWithResponse sends given HTTP request and returns response
	DoHTTPRequestWithResponse(req *http.Request, requestCallback RequestCallback) (*http.Response, error)
	// SetAuthorization sets the authorization header value
	SetAuthorization(authorization string)
	// Authorization returns current authorization header value
	Authorization() string
	// ServerAPIURL returns URL to InfluxDB2 server API space
	ServerAPIURL() string
	// ServerURL returns URL to InfluxDB2 server
	ServerURL() string
}

Service handles HTTP operations with taking care of mandatory request headers and known errors

func NewService

func NewService(serverURL, authorization string, httpOptions *Options) Service

NewService creates instance of http Service with given parameters

Jump to

Keyboard shortcuts

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