Documentation ¶
Index ¶
- Constants
- Variables
- func AddPaddingOnUpperCase(s string) string
- func AppendError(original, incoming error) error
- func ChangePermission(directory string) error
- func CreateDir(dir string) error
- func EncodeURLValues(urlPath string, values url.Values) string
- func ExcludeError(err, excl error) error
- func ExtractHost(address string) string
- func ExtractPort(host string) int
- func GenerateRandomString(length uint, characters ...string) (string, error)
- func GetDefaultDataDir(env string) string
- func GetExecutablePath() (string, error)
- func GetTypeAssertError(required string, received interface{}, fieldDescription ...string) error
- func GetURIPath(uri string) string
- func InArray(val, array interface{}) (exists bool, index int)
- func IsEnabled(isEnabled bool) string
- func IsValidCryptoAddress(address, crypto string) (bool, error)
- func MatchesEmailPattern(value string) bool
- func NewHTTPClientWithTimeout(t time.Duration) *http.Client
- func SendHTTPRequest(ctx context.Context, method, urlPath string, headers map[string]string, ...) ([]byte, error)
- func SetHTTPClient(client *http.Client) error
- func SetHTTPClientWithTimeout(t time.Duration) error
- func SetHTTPUserAgent(agent string) error
- func SplitStringSliceByLimit(in []string, limit uint) [][]string
- func StartEndTimeCheck(start, end time.Time) error
- func StringDataCompare(haystack []string, needle string) bool
- func StringDataCompareInsensitive(haystack []string, needle string) bool
- func StringDataContains(haystack []string, needle string) bool
- func StringDataContainsInsensitive(haystack []string, needle string) bool
- func StringSliceDifference(slice1, slice2 []string) []string
- func YesOrNo(input string) bool
- type ErrorCollector
Constants ¶
const ( // SimpleTimeFormatWithTimezone a common, but non-implemented time format in golang SimpleTimeFormatWithTimezone = time.DateTime + " MST" // GctExt is the extension for GCT Tengo script files GctExt = ".gct" )
const ( SmallLetters = "abcdefghijklmnopqrstuvwxyz" CapitalLetters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" NumberCharacters = "0123456789" )
Strings representing the full lower, upper case English character alphabet and base-10 numbers for generating a random string.
Variables ¶
var ( // ErrNotYetImplemented defines a common error across the code base that // alerts of a function that has not been completed or tied into main code ErrNotYetImplemented = errors.New("not yet implemented") // ErrFunctionNotSupported defines a standardised error for an unsupported // wrapper function by an API ErrFunctionNotSupported = errors.New("unsupported wrapper function") // ErrDateUnset is an error for start end check calculations ErrDateUnset = errors.New("date unset") // ErrStartAfterEnd is an error for start end check calculations ErrStartAfterEnd = errors.New("start date after end date") // ErrStartEqualsEnd is an error for start end check calculations ErrStartEqualsEnd = errors.New("start date equals end date") // ErrStartAfterTimeNow is an error for start end check calculations ErrStartAfterTimeNow = errors.New("start date is after current time") // ErrNilPointer defines an error for a nil pointer ErrNilPointer = errors.New("nil pointer") // ErrCannotCalculateOffline is returned when a request wishes to calculate // something offline, but has an online requirement ErrCannotCalculateOffline = errors.New("cannot calculate offline, unsupported") // ErrNoResponse is returned when a response has no entries/is empty // when one is expected ErrNoResponse = errors.New("no response") // ErrTypeAssertFailure defines an error when type assertion fails ErrTypeAssertFailure = errors.New("type assert failure") )
Vars for common.go operations
Functions ¶
func AddPaddingOnUpperCase ¶
AddPaddingOnUpperCase adds padding to a string when detecting an upper case letter. If there are multiple upper case items like `ThisIsHTTPExample`, it will only pad between like this `This Is HTTP Example`.
func AppendError ¶
AppendError appends an error to a list of exesting errors Either argument may be: * A vanilla error * An error implementing Unwrap() []error e.g. fmt.Errorf("%w: %w") * nil The result will be an error which may be a multiError if multipleErrors were found
func ChangePermission ¶
ChangePermission lists all the directories and files in an array
func EncodeURLValues ¶
EncodeURLValues concatenates url values onto a url string and returns a string
func ExcludeError ¶
ExcludeError returns a new error excluding any errors matching excl For a standard error it will either return the error unchanged or nil For an error which implements Unwrap() []error it will remove any errors matching excl and return the remaining errors or nil Any non-error messages and formatting from fmt.Errorf will be lost; This function is written for conditions
func ExtractHost ¶
ExtractHost returns the hostname out of a string
func ExtractPort ¶
ExtractPort returns the port name out of a string
func GenerateRandomString ¶
GenerateRandomString generates a random string provided a length and list of Character types { SmallLetters, CapitalLetters, NumberCharacters}. if no characters are provided, the function uses a NumberCharacters(string of numeric characters).
func GetDefaultDataDir ¶
GetDefaultDataDir returns the default data directory Windows - C:\Users\%USER%\AppData\Roaming\GoCryptoTrader Linux/Unix or OSX - $HOME/.gocryptotrader
func GetExecutablePath ¶
GetExecutablePath returns the executables launch path
func GetTypeAssertError ¶
GetTypeAssertError returns additional information for when an assertion failure occurs. fieldDescription is an optional way to return what the affected field was for
func GetURIPath ¶
GetURIPath returns the path of a URL given a URI
func IsEnabled ¶
IsEnabled takes in a boolean param and returns a string if it is enabled or disabled
func IsValidCryptoAddress ¶
IsValidCryptoAddress validates your cryptocurrency address string using the regexp package // Validation issues occurring because "3" is contained in litecoin and Bitcoin addresses - non-fatal
func MatchesEmailPattern ¶
MatchesEmailPattern ensures that the string is an email address by regexp check
func NewHTTPClientWithTimeout ¶
NewHTTPClientWithTimeout initialises a new HTTP client and its underlying transport IdleConnTimeout with the specified timeout duration
func SendHTTPRequest ¶
func SendHTTPRequest(ctx context.Context, method, urlPath string, headers map[string]string, body io.Reader, verbose bool) ([]byte, error)
SendHTTPRequest sends a request using the http package and returns the body contents
func SetHTTPClient ¶
SetHTTPClient sets a custom HTTP client.
func SetHTTPClientWithTimeout ¶
SetHTTPClientWithTimeout sets a new *http.Client with different timeout settings
func SetHTTPUserAgent ¶
SetHTTPUserAgent sets the user agent which will be used for all common HTTP requests.
func SplitStringSliceByLimit ¶
SplitStringSliceByLimit splits a slice of strings into slices by input limit and returns a slice of slice of strings
func StartEndTimeCheck ¶
StartEndTimeCheck provides some basic checks which occur frequently in the codebase
func StringDataCompare ¶
StringDataCompare data checks the substring array with an input and returns a bool
func StringDataCompareInsensitive ¶
StringDataCompareInsensitive data checks the substring array with an input and returns a bool irrespective of lower or upper case strings
func StringDataContains ¶
StringDataContains checks the substring array with an input and returns a bool
func StringDataContainsInsensitive ¶
StringDataContainsInsensitive checks the substring array with an input and returns a bool irrespective of lower or upper case strings
func StringSliceDifference ¶
StringSliceDifference concatenates slices together based on its index and returns an individual string array
Types ¶
type ErrorCollector ¶
ErrorCollector allows collecting a stream of errors from concurrent go routines Users should call e.Wg.Done and send errors to e.C
func CollectErrors ¶
func CollectErrors(n int) *ErrorCollector
CollectErrors returns an ErrorCollector with WaitGroup and Channel buffer set to n
func (*ErrorCollector) Collect ¶
func (e *ErrorCollector) Collect() (errs error)
Collect runs waits for e.Wg to be Done, closes the error channel, and return a error collection