client

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2023 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrRegAccount            = errors.New("client: failed to register an account")
	ErrUpdateAccount         = errors.New("client: failed to update the account data")
	ErrEncodeAccount         = errors.New("client: failed to encode account data")
	ErrDecodeAccount         = errors.New("client: failed to decode account data")
	ErrGetAccountData        = errors.New("client: failed to get the account data")
	ErrFetchingConfiguration = errors.New("client: error fetching configuration")
)

Functions

This section is empty.

Types

type Account

type Account struct {
	ID      string `json:"id"`
	Account struct {
		License string `json:"license"`
	} `json:"account"`
	Token string `json:"token"`
}

Account represents a registered CF account.

type Client

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

func NewClient

func NewClient(config *Configuration, logging bool) *Client

func (*Client) AddReferrer

func (c *Client) AddReferrer(ctx context.Context, acc, referrer *Account) error

func (*Client) ApplyKey

func (c *Client) ApplyKey(ctx context.Context, acc *Account, key string) error

func (*Client) Do

func (c *Client) Do(req *http.Request) (*http.Response, error)

func (*Client) GetAccountData

func (c *Client) GetAccountData(ctx context.Context, acc *Account) (*models.Account, error)

func (*Client) NewAccount

func (c *Client) NewAccount(ctx context.Context) (*Account, error)

func (*Client) NewAccountWithLicense

func (c *Client) NewAccountWithLicense(ctx context.Context) (*models.Account, error)

NewAccountWithLicense creates models.Account with random license.

func (*Client) RemoveDevice

func (c *Client) RemoveDevice(ctx context.Context, acc *Account) error

func (*Client) UpdateConfig

func (c *Client) UpdateConfig(config *ConfigurationData)

type Configuration

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

Configuration wraps ConfigurationData with a mutex to allow goroutine-safe access.

func NewConfiguration

func NewConfiguration() *Configuration

func (*Configuration) BaseURL

func (cc *Configuration) BaseURL() string

func (*Configuration) CFClientVersion

func (cc *Configuration) CFClientVersion() string

func (*Configuration) Data

func (cc *Configuration) Data() ConfigurationData

Data returns a copy of stored data.

func (*Configuration) Host

func (cc *Configuration) Host() string

func (*Configuration) Keys

func (cc *Configuration) Keys() []string

func (*Configuration) Update

func (cc *Configuration) Update(updated *ConfigurationData)

func (*Configuration) UserAgent

func (cc *Configuration) UserAgent() string

func (*Configuration) WaitTime

func (cc *Configuration) WaitTime() time.Duration

type ConfigurationData

type ConfigurationData struct {
	CFClientVersion string
	UserAgent       string
	Host            string
	BaseURL         string
	Keys            []string
	WaitTime        time.Duration
}

ConfigurationData is the configuration required for the client to work.

func DefaultConfigurationData

func DefaultConfigurationData() *ConfigurationData

DefaultConfigurationData returns usable default configuration.

func GetConfiguration

func GetConfiguration(ctx context.Context, url string) (*ConfigurationData, error)

GetConfiguration returns a new configuration parsed from the url, or an error if it fails to parse.

Jump to

Keyboard shortcuts

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