common

package
v0.0.0-...-3240a16 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2017 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HashSHA1 = iota
	HashSHA256
	HashSHA512
	HashSHA512_384
	SatoshisPerBTC = 100000000
	SatoshisPerLTC = 100000000
	WeiPerEther    = 1000000000000000000
)

Const declarations for common.go operations

Variables

This section is empty.

Functions

func Base64Decode

func Base64Decode(input string) ([]byte, error)

Base64Decode takes in a Base64 string and returns a byte array and an error

func Base64Encode

func Base64Encode(input []byte) string

Base64Encode takes in a byte array then returns an encoded base64 string

func CalculateAmountWithFee

func CalculateAmountWithFee(amount, fee float64) float64

CalculateAmountWithFee returns a calculated fee included amount on fee

func CalculateFee

func CalculateFee(amount, fee float64) float64

CalculateFee returns a simple fee on amount

func CalculateNetProfit

func CalculateNetProfit(amount, priceThen, priceNow, costs float64) float64

CalculateNetProfit returns net profit

func CalculatePercentageDifference

func CalculatePercentageDifference(amount, secondAmount float64) float64

CalculatePercentageDifference returns the percentage of difference between multiple time periods

func CalculatePercentageGainOrLoss

func CalculatePercentageGainOrLoss(priceNow, priceThen float64) float64

CalculatePercentageGainOrLoss returns the percentage rise over a certain period

func DataContains

func DataContains(haystack []string, needle string) bool

DataContains checks the substring array with an input and returns a bool

func EncodeURLValues

func EncodeURLValues(url string, values url.Values) string

EncodeURLValues concatenates url values onto a url string and returns a string

func ExtractHost

func ExtractHost(address string) string

ExtractHost returns the hostname out of a string

func ExtractPort

func ExtractPort(host string) int

ExtractPort returns the port name out of a string

func GetHMAC

func GetHMAC(hashType int, input, key []byte) []byte

GetHMAC returns a keyed-hash message authentication code using the desired hashtype

func GetMD5

func GetMD5(input []byte) []byte

GetMD5 returns a MD5 hash of a byte array

func GetSHA256

func GetSHA256(input []byte) []byte

GetSHA256 returns a SHA256 hash of a byte array

func GetSHA512

func GetSHA512(input []byte) []byte

GetSHA512 returns a SHA512 hash of a byte array

func GetURIPath

func GetURIPath(uri string) string

GetURIPath returns the path of a URL given a URI

func HexEncodeToString

func HexEncodeToString(input []byte) string

HexEncodeToString takes in a hexadecimal byte array and returns a string

func IsEnabled

func IsEnabled(isEnabled bool) string

IsEnabled takes in a boolean param and returns a string if it is enabled or disabled

func IsValidCryptoAddress

func IsValidCryptoAddress(address, crypto string) (bool, error)

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 JSONDecode

func JSONDecode(data []byte, to interface{}) error

JSONDecode decodes JSON data into a structure

func JSONEncode

func JSONEncode(v interface{}) ([]byte, error)

JSONEncode encodes structure data into JSON

func JoinStrings

func JoinStrings(input []string, separator string) string

JoinStrings joins an array together with the required separator and returns it as a string

func OutputCSV

func OutputCSV(path string, data [][]string) error

OutputCSV dumps data into a file as comma-separated values

func ReadFile

func ReadFile(path string) ([]byte, error)

ReadFile reads a file and returns read data as byte array.

func RemoveFile

func RemoveFile(file string) error

RemoveFile removes a file

func ReplaceString

func ReplaceString(input, old, new string, n int) string

ReplaceString replaces a string with another

func RoundFloat

func RoundFloat(x float64, prec int) float64

RoundFloat rounds your floating point number to the desired decimal place

func SendHTTPGetRequest

func SendHTTPGetRequest(url string, jsonDecode bool, result interface{}) error

SendHTTPGetRequest sends a simple get request using a url string & JSON decodes the response into a struct pointer you have supplied. Returns an error on failure.

func SendHTTPRequest

func SendHTTPRequest(method, path string, headers map[string]string, body io.Reader) (string, error)

SendHTTPRequest sends a request using the http package and returns a response as a string and an error

func SplitStrings

func SplitStrings(input, separator string) []string

SplitStrings splits blocks of strings from string into a string array using a separator ie "," or "_"

func StringContains

func StringContains(input, substring string) bool

StringContains checks a substring if it contains your input then returns a bool

func StringSliceDifference

func StringSliceDifference(slice1 []string, slice2 []string) []string

StringSliceDifference concatenates slices together based on its index and returns an individual string array

func StringToLower

func StringToLower(input string) string

StringToLower changes strings to lowercase

func StringToUpper

func StringToUpper(input string) string

StringToUpper changes strings to uppercase

func TrimString

func TrimString(input, cutset string) string

TrimString trims unwanted prefixes or postfixes

func UnixTimestampStrToTime

func UnixTimestampStrToTime(timeStr string) (time.Time, error)

UnixTimestampStrToTime returns a time.time and an error

func UnixTimestampToTime

func UnixTimestampToTime(timeint64 int64) time.Time

UnixTimestampToTime returns time.time

func WriteFile

func WriteFile(file string, data []byte) error

WriteFile writes selected data to a file and returns an error

func YesOrNo

func YesOrNo(input string) bool

YesOrNo returns a boolean variable to check if input is "y" or "yes"

Types

This section is empty.

Jump to

Keyboard shortcuts

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