config

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2019 License: BSD-2-Clause Imports: 8 Imported by: 0

Documentation

Overview

Package config provides configuration for client apps based on the Cryptowatch SDK.

Index

Constants

View Source
const (
	DefaultAPIURL    = "https://api.cryptowat.ch"
	DefaultStreamURL = "wss://stream.cryptowat.ch"
	DefaultTradeURL  = "wss://trading.service.cryptowat.ch"

	Filepath = ".cw/credentials.yml"
)

Default URLs used if one of the URLs isn't specified.

Variables

View Source
var (
	ErrNilConfig      = Error{Type: "config", Why: "config is nil", How: "create and load config first"}
	ErrEmptyAPIKey    = Error{Type: "config", What: "api_url", Why: "is empty", How: "specify an api_key"}
	ErrEmptySecretKey = Error{Type: "config", What: "secret_key", Why: "is empty", How: "specify a secret_key"}
	ErrInvalidHTTPURL = Error{Type: "config", Why: "wrong url", How: "URL must be a valid http or https url"}
	ErrInvalidWSURL   = Error{Type: "config", Why: "wrong url", How: "URL must be a valid ws or wss url"}
	ErrInvalidScheme  = Error{Type: "config", Why: "invalid scheme", How: "scheme must be http(s) or ws(s)"}

	ErrNilArgs = Error{Type: "args", Why: "args is nil", How: "create an instance of args"}
)

Various validation errors.

Functions

func CheckURL

func CheckURL(given string, schemes ...string) error

CheckURL checks that the url has the correct scheme.

func DefaultFilepath

func DefaultFilepath() (string, error)

DefaultFilepath determines and returns default config path. It can return an error if detecting the user's home directory has failed.

func ValidateCWDefault

func ValidateCWDefault(c *CW) error

ValidateCWDefault performs validation of the given config by checking all the fields for correctness. It does set default values for an url if one wasn't specified.

Types

type CW

type CW struct {
	APIKey    string `yaml:"api_key"`
	SecretKey string `yaml:"secret_key"`
	StreamURL string `yaml:"stream_url"`
	TradeURL  string `yaml:"trade_url"`
	APIURL    string `yaml:"api_url"`
	// contains filtered or unexported fields
}

CW holds the configuration.

func New

func New(name string) (*CW, error)

New creates a new CW from a file by the given name.

func NewFromFilename

func NewFromFilename(filename string) (*CW, error)

NewFromFilename creates a new CW from a file by the given filename.

func NewFromRaw

func NewFromRaw(raw []byte) (*CW, error)

NewFromRaw creates a new CW by unmarshaling the given raw data.

func (*CW) Example

func (c *CW) Example() *CW

func (*CW) String

func (c *CW) String() string

String can't be defined on a value receiver here because of the mutex.

func (*CW) Validate

func (c *CW) Validate() error

Validate validates the config by applying ValidatorDefault.

func (*CW) ValidateFunc

func (c *CW) ValidateFunc(vfs ...ValidateFuncCW) error

ValidateFunc validates the config by applying each of given vfs to it.

type Error

type Error struct {
	Type string
	What string
	Why  string
	How  string
}

Error holds detials about an error occured during validation process.

func (Error) Error

func (e Error) Error() string

type ValidateFuncCW

type ValidateFuncCW func(*CW) error

ValidateFuncCW takes an instance of CW and returns an error if any occured during validation process.

Jump to

Keyboard shortcuts

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