client

package
v0.1.18 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2024 License: Unlicense Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Logformat

func Logformat(out io.Writer, args *log.FormatterArgs) (n int, err error)

Types

type Client

type Client struct {
	AgentSymbol     string
	MetricsReporter metrics.MetricsReporter
	CacheClient     *cache.Cache
	Logger          *log.Logger
	RateLimiter     *RateLimiter
	// contains filtered or unexported fields
}

Client represents the SpaceTraders API client

func NewClient

func NewClient(options ClientOptions) (*Client, error)

NewClient creates a new instance of the SpaceTraders API client

func (*Client) ConfigureMetricsClient

func (c *Client) ConfigureMetricsClient(url, token, org, bucket string)

func (*Client) Delete

func (c *Client) Delete(endpoint string, queryParams map[string]string, result interface{}) *models.APIError

Delete sends a DELETE request to the specified endpoint with optional query parameters

func (*Client) Get

func (c *Client) Get(endpoint string, queryParams map[string]string, result interface{}) *models.APIError

Get sends a GET request to the specified endpoint with optional query parameters

func (*Client) GetToken

func (c *Client) GetToken() string

func (*Client) MetricBuilder

func (c *Client) MetricBuilder() *metrics.MetricBuilder

func (*Client) Patch

func (c *Client) Patch(endpoint string, body interface{}, queryParams map[string]string, result interface{}) *models.APIError

Patch sends a PATCH request to the specified endpoint with optional query parameters

func (*Client) Post

func (c *Client) Post(endpoint string, body interface{}, queryParams map[string]string, result interface{}) *models.APIError

Post sends a POST request to the specified endpoint with optional query parameters

func (*Client) Put

func (c *Client) Put(endpoint string, body interface{}, queryParams map[string]string, result interface{}) *models.APIError

Put sends a PUT request to the specified endpoint with optional query parameters

func (*Client) WriteMetric

func (c *Client) WriteMetric(metric metrics.Metric)

type ClientOptions

type ClientOptions struct {
	BaseURL           string
	Symbol            string
	Faction           string
	Email             string
	RequestsPerSecond float32
	LogLevel          log.Level
	RetryDelay        time.Duration
}

ClientOptions represents the configuration options for the SpaceTraders API client

func DefaultClientOptions

func DefaultClientOptions() ClientOptions

DefaultClientOptions returns the default configuration options for the SpaceTraders API client

type Glog

type Glog struct {
	Logger log.Logger
}

type Paginator

type Paginator[T any] struct {
	Data []T
	Meta models.Meta // Use value instead of pointer to simplify usage

	Error error
	// contains filtered or unexported fields
}

Paginator is a generic struct for pagination, where T is the type of data being paginated. It abstracts away the pagination logic, allowing users to fetch pages of data seamlessly.

func NewPaginator

func NewPaginator[T any](fetchFunc func(models.Meta) ([]T, models.Meta, error)) *Paginator[T]

NewPaginator creates a new Paginator instance with default pagination parameters. fetchFunc is a function that knows how to fetch a page of data given pagination metadata.

func (*Paginator[T]) FetchAllPages

func (p *Paginator[T]) FetchAllPages() ([]T, error)

FetchAllPages fetches all data at once without needing to loop over paginators.

type RateLimiter added in v0.1.17

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

func NewRateLimiter added in v0.1.17

func NewRateLimiter(staticRate, burstRate float64) *RateLimiter

func (*RateLimiter) Wait added in v0.1.17

func (rl *RateLimiter) Wait(ctx context.Context) error

type RegisterRequest

type RegisterRequest struct {
	Faction string `json:"faction"`
	Symbol  string `json:"symbol"`
	Email   string `json:"email,omitempty"`
}

RegisterRequest represents the request payload for registering a new agent

type RegisterResponse

type RegisterResponse struct {
	Data struct {
		Agent    models.Agent    `json:"agent"`
		Contract models.Contract `json:"contract"`
		Faction  models.Faction  `json:"faction"`
		Ship     models.Ship     `json:"ship"`
		Token    string          `json:"token"`
	} `json:"data"`
}

RegisterResponse represents the response payload for registering a new agent

type TokenFile

type TokenFile struct {
	Tokens map[string]string `json:"tokens"`
}

TokenFile represents the structure of the token file

Jump to

Keyboard shortcuts

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