api

package
v0.0.0-...-e107611 Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2024 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var UserAgent = "qbee-agent/" + app.Version

UserAgent is the user agent string used for all API calls. This is used to identify active versions of the agent.

Functions

func NewError

func NewError(responseStatusCode int, responseBody io.Reader) error

NewError returns a new API error with the given response status code and body.

func NewMockedClient

func NewMockedClient() (*Client, *Mock)

NewMockedClient returns a new API client with mocked transport.

func UseProxy

func UseProxy(proxy *Proxy) error

UseProxy sets HTTP_PROXY environmental variable, so HTTP clients can make use of it.

Types

type Client

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

Client is a device hub API client.

func NewClient

func NewClient(host, port string) *Client

NewClient returns a new device hub client.

func (*Client) Do

func (cli *Client) Do(request *http.Request) (*http.Response, error)

Do sends an HTTP request and returns an HTTP response.

func (*Client) Get

func (cli *Client) Get(ctx context.Context, path string, dst any) error

Get sends a GET request to device hub.

func (*Client) Make

func (cli *Client) Make(request *http.Request, dst any) error

Make sends an API request and optionally parses response body into dst.

func (*Client) NewRequest

func (cli *Client) NewRequest(ctx context.Context, method, path string, src any) (*http.Request, error)

NewRequest returns a new HTTP request for provided method, path and src.

func (*Client) Post

func (cli *Client) Post(ctx context.Context, path string, src, dst any) error

Post sends a POST request to device hub.

func (*Client) Put

func (cli *Client) Put(ctx context.Context, path string, src, dst any) error

Put sends a PUT request to device hub.

func (*Client) WithTLSConfig

func (cli *Client) WithTLSConfig(config *tls.Config) *Client

WithTLSConfig sets the TLS config used by the HTTP client.

type ConnectionError

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

ConnectionError is used to explicitly indicate API connectivity issue. This is used to track failed API connection attempts.

func NewConnectionError

func NewConnectionError(err error) ConnectionError

NewConnectionError returns a new connection error with the given underlying error.

func (ConnectionError) Error

func (err ConnectionError) Error() string

Error returns a string representation of the error.

func (ConnectionError) Unwrap

func (err ConnectionError) Unwrap() error

Unwrap returns the underlying error.

type Error

type Error struct {
	ResponseCode int
	ResponseBody []byte
}

Error returned when HTTP API request results in status code >= 400.

func (*Error) Error

func (err *Error) Error() string

Error returns a string representation of the error.

type Mock

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

Mock is a mock RoundTripper implementation.

func (*Mock) Add

func (m *Mock) Add(statusCode int, body string, args ...any) *MockResponse

Add adds a new mock response with the given status code and body. Response body can contain format specifiers.

func (*Mock) AddResponse

func (m *Mock) AddResponse(response *http.Response) *MockResponse

AddResponse adds a new mock response.

func (*Mock) RoundTrip

func (m *Mock) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip is the RoundTripper interface implementation, so we can use this in http.Client.

type MockResponse

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

MockResponse represents a mock response with the request that was used to get it.

func (*MockResponse) Called

func (resp *MockResponse) Called() bool

Called returns true if the response was used.

func (*MockResponse) Request

func (resp *MockResponse) Request() *http.Request

Request returns the request that was used to get this response.

type Proxy

type Proxy struct {
	Host     string
	Port     string
	User     string
	Password string
}

Proxy represents a proxy server configuration.

Jump to

Keyboard shortcuts

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