config

package
v0.0.0-...-cf2d4bb Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2017 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EncryptedConfigFile = "config.dat"
	ConfigFile          = "config.json"
	ConfigTestFile      = "../testdata/configtest.json"
)

Constants declared here are filename strings and test strings

View Source
const (
	// EncryptConfirmString has a the general confirmation string to allow us to
	// see if the file is correctly encrypted
	EncryptConfirmString = "THORS-HAMMER"
)

Variables

View Source
var (
	ErrExchangeNameEmpty                            = "Exchange #%d in config: Exchange name is empty."
	ErrExchangeAvailablePairsEmpty                  = "Exchange %s: Available pairs is empty."
	ErrExchangeEnabledPairsEmpty                    = "Exchange %s: Enabled pairs is empty."
	ErrExchangeBaseCurrenciesEmpty                  = "Exchange %s: Base currencies is empty."
	ErrExchangeNotFound                             = "Exchange %s: Not found."
	ErrNoEnabledExchanges                           = "No Exchanges enabled."
	ErrCryptocurrenciesEmpty                        = "Cryptocurrencies variable is empty."
	ErrFailureOpeningConfig                         = "Fatal error opening %s file. Error: %s"
	ErrCheckingConfigValues                         = "Fatal error checking config values. Error: %s"
	ErrSavingConfigBytesMismatch                    = "Config file %q bytes comparison doesn't match, read %s expected %s."
	WarningSMSGlobalDefaultOrEmptyValues            = "WARNING -- SMS Support disabled due to default or empty Username/Password values."
	WarningSSMSGlobalSMSContactDefaultOrEmptyValues = "WARNING -- SMS contact #%d Name/Number disabled due to default or empty values."
	WarningSSMSGlobalSMSNoContacts                  = "WARNING -- SMS Support disabled due to no enabled contacts."
	WarningWebserverCredentialValuesEmpty           = "WARNING -- Webserver support disabled due to empty Username/Password values."
	WarningWebserverListenAddressInvalid            = "WARNING -- Webserver support disabled due to invalid listen address."
	WarningWebserverRootWebFolderNotFound           = "WARNING -- Webserver support disabled due to missing web folder."
	WarningExchangeAuthAPIDefaultOrEmptyValues      = "WARNING -- Exchange %s: Authenticated API support disabled due to default/empty APIKey/Secret/ClientID values."
	WarningCurrencyExchangeProvider                 = "WARNING -- Currency exchange provider invalid valid. Reset to Fixer."
	Cfg                                             Config
)

Variables here are mainly alerts and a configuration object

Functions

func ConfirmConfigJSON

func ConfirmConfigJSON(file []byte, result interface{}) error

ConfirmConfigJSON confirms JSON in file

func ConfirmECS

func ConfirmECS(file []byte) bool

ConfirmECS confirms that the encryption confirmation string is found

func DecryptConfigFile

func DecryptConfigFile(configData, key []byte) ([]byte, error)

DecryptConfigFile decrypts configuration data with the supplied key and returns the un-encrypted file as a byte array with an error

func EncryptConfigFile

func EncryptConfigFile(configData, key []byte) ([]byte, error)

EncryptConfigFile encrypts configuration data that is parsed in with a key and returns it as a byte array with an error

func GetFilePath

func GetFilePath(file string) string

GetFilePath returns the desired config file or the default config file name based on if the application is being run under test or normal mode.

func PromptForConfigKey

func PromptForConfigKey() ([]byte, error)

PromptForConfigKey asks for configuration key

func RemoveECS

func RemoveECS(file []byte) []byte

RemoveECS removes encryption confirmation string

Types

type Config

type Config struct {
	Name                     string
	EncryptConfig            int
	Cryptocurrencies         string
	CurrencyExchangeProvider string
	CurrencyPairFormat       *CurrencyPairFormatConfig `json:"CurrencyPairFormat"`
	FiatDisplayCurrency      string
	Portfolio                portfolio.Base   `json:"PortfolioAddresses"`
	SMS                      SMSGlobalConfig  `json:"SMSGlobal"`
	Webserver                WebserverConfig  `json:"Webserver"`
	Exchanges                []ExchangeConfig `json:"Exchanges"`
}

Config is the overarching object that holds all the information for prestart management of portfolio, SMSGlobal, webserver and enabled exchange

func GetConfig

func GetConfig() *Config

GetConfig returns a pointer to a confiuration object

func (*Config) CheckExchangeConfigValues

func (c *Config) CheckExchangeConfigValues() error

CheckExchangeConfigValues returns configuation values for all enabled exchanges

func (*Config) CheckSMSGlobalConfigValues

func (c *Config) CheckSMSGlobalConfigValues() error

CheckSMSGlobalConfigValues checks concurrent SMSGlobal configurations

func (*Config) CheckWebserverConfigValues

func (c *Config) CheckWebserverConfigValues() error

CheckWebserverConfigValues checks information before webserver starts and returns an error if values are incorrect.

func (*Config) GetConfigEnabledExchanges

func (c *Config) GetConfigEnabledExchanges() int

GetConfigEnabledExchanges returns the number of exchanges that are enabled.

func (*Config) GetCurrencyPairDisplayConfig

func (c *Config) GetCurrencyPairDisplayConfig() *CurrencyPairFormatConfig

GetCurrencyPairDisplayConfig retrieves the currency pair display preference

func (*Config) GetExchangeConfig

func (c *Config) GetExchangeConfig(name string) (ExchangeConfig, error)

GetExchangeConfig returns your exchange configurations by its indivdual name

func (*Config) LoadConfig

func (c *Config) LoadConfig(configPath string) error

LoadConfig loads your configuration file into your configuration object

func (*Config) PromptForConfigEncryption

func (c *Config) PromptForConfigEncryption() bool

PromptForConfigEncryption asks for encryption key

func (*Config) ReadConfig

func (c *Config) ReadConfig(configPath string) error

ReadConfig verifies and checks for encryption and verifies the unencrypted file contains JSON.

func (*Config) RetrieveConfigCurrencyPairs

func (c *Config) RetrieveConfigCurrencyPairs() error

RetrieveConfigCurrencyPairs splits, assigns and verifies enabled currency pairs either cryptoCurrencies or fiatCurrencies

func (*Config) SaveConfig

func (c *Config) SaveConfig(configPath string) error

SaveConfig saves your configuration to your desired path

func (*Config) UpdateConfig

func (c *Config) UpdateConfig(configPath string, newCfg Config) error

UpdateConfig updates the config with a supplied config file

func (*Config) UpdateExchangeConfig

func (c *Config) UpdateExchangeConfig(e ExchangeConfig) error

UpdateExchangeConfig updates exchange configurations

type CurrencyPairFormatConfig

type CurrencyPairFormatConfig struct {
	Uppercase bool
	Delimiter string `json:",omitempty"`
	Separator string `json:",omitempty"`
	Index     string `json:",omitempty"`
}

CurrencyPairFormatConfig stores the users preferred currency pair display

type ExchangeConfig

type ExchangeConfig struct {
	Name                      string
	Enabled                   bool
	Verbose                   bool
	Websocket                 bool
	UseSandbox                bool
	RESTPollingDelay          time.Duration
	AuthenticatedAPISupport   bool
	APIKey                    string
	APISecret                 string
	ClientID                  string `json:",omitempty"`
	AvailablePairs            string
	EnabledPairs              string
	BaseCurrencies            string
	AssetTypes                string
	ConfigCurrencyPairFormat  *CurrencyPairFormatConfig `json:"ConfigCurrencyPairFormat"`
	RequestCurrencyPairFormat *CurrencyPairFormatConfig `json:"RequestCurrencyPairFormat"`
}

ExchangeConfig holds all the information needed for each enabled Exchange.

type Post

type Post struct {
	Data Config `json:"Data"`
}

Post holds the bot configuration data

type SMSGlobalConfig

type SMSGlobalConfig struct {
	Enabled  bool
	Username string
	Password string
	Contacts []smsglobal.Contact
}

SMSGlobalConfig structure holds all the variables you need for instant messaging and broadcast used by SMSGlobal

type WebserverConfig

type WebserverConfig struct {
	Enabled                      bool
	AdminUsername                string
	AdminPassword                string
	ListenAddress                string
	WebsocketConnectionLimit     int
	WebsocketAllowInsecureOrigin bool
}

WebserverConfig struct holds the prestart variables for the webserver.

Jump to

Keyboard shortcuts

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