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 ¶
- type Doer
- type Error
- type Options
- func (o *Options) ApplicationName() string
- func (o *Options) HTTPClient() *http.Client
- func (o *Options) HTTPDoer() Doer
- func (o *Options) HTTPRequestTimeout() uint
- func (o *Options) OwnHTTPClient() bool
- func (o *Options) SetApplicationName(appName string) *Options
- func (o *Options) SetHTTPClient(c *http.Client) *Options
- func (o *Options) SetHTTPDoer(d Doer) *Options
- func (o *Options) SetHTTPRequestTimeout(httpRequestTimeout uint) *Options
- func (o *Options) SetTLSConfig(tlsConfig *tls.Config) *Options
- func (o *Options) TLSConfig() *tls.Config
- type RequestCallback
- type ResponseCallback
- type Service
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Error ¶
Error represent error response from InfluxDBServer or http 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) ApplicationName ¶
ApplicationName returns application name used in the User-Agent HTTP header
func (*Options) HTTPClient ¶
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) HTTPRequestTimeout ¶
HTTPRequestTimeout returns HTTP request timeout
func (*Options) OwnHTTPClient ¶
OwnHTTPClient returns true of HTTP client was created internally. False if it was set externally.
func (*Options) SetApplicationName ¶
SetApplicationName sets an application name to the User-Agent HTTP header
func (*Options) SetHTTPClient ¶
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 ¶
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 ¶
SetHTTPRequestTimeout sets HTTP request timeout in sec
func (*Options) SetTLSConfig ¶
SetTLSConfig sets TLS configuration for secure connection
type RequestCallback ¶
RequestCallback defines function called after a request is created before any call
type ResponseCallback ¶
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 ¶
NewService creates instance of http Service with given parameters