client

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: May 28, 2024 License: BSD-3-Clause Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultClientTimeout = 10 * time.Second
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	HTTP *resty.Client
	// contains filtered or unexported fields
}

Client defines an HTTP client for the REST API.

func New

func New(
	apiURL string,
	reader EventReader,
	logger *slog.Logger,
) *Client

New returns a new client with the specified API key and config.

func (*Client) Call

func (c *Client) Call(ctx context.Context, method, path string, params, response any, opts ...model.RequestOption) error

Call makes an API call based on the request params and options. The response is automatically unmarshaled.

func (*Client) CallURL

func (c *Client) CallURL(ctx context.Context, method, uri string, response any, opts ...model.RequestOption) error

CallURL makes an API call based on a request URI and options. The response is automatically unmarshaled.

func (*Client) Listen

func (c *Client) Listen(ctx context.Context, path string, params any, handler EventStreamHandler, opts ...model.RequestOption) error

Listen to an event data stream. This is a blocking call that will continue to read from the stream until the context is canceled or the watch is stopped.

func (*Client) SetBasicAuth

func (c *Client) SetBasicAuth(apiKey, apiSecret string) *Client

func (*Client) SetHeader

func (c *Client) SetHeader(key, value string) *Client

type Event

type Event interface {
	GetData() []byte
	GetTimestamp() time.Time
}

type EventReader

type EventReader interface {
	Listen(ctx context.Context, stream io.Reader) (<-chan Event, <-chan error)
}

type EventStreamHandler

type EventStreamHandler func(ctx context.Context, event Event) error

Jump to

Keyboard shortcuts

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