utils

package module
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2022 License: MIT Imports: 20 Imported by: 4

README

Utils

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Apr2Apy added in v0.0.5

func Apr2Apy[T types.Number](apr T) (apy float64)

Compound times = 365.

Input 0.01 for 1%.

func Apr2ApyWithCompoundTimes added in v0.0.5

func Apr2ApyWithCompoundTimes[T types.Number, S types.Number](apr T, compoundTimes S) (apy float64)

Input 0.01 for 1%.

func Apy2Apr added in v0.0.5

func Apy2Apr[T types.Number](apy T) (apr float64)

Compound times = 365.

Input 0.01 for 1%.

func Apy2AprWithCompoundTimes added in v0.0.5

func Apy2AprWithCompoundTimes[T types.Number, S types.Number](apy T, compoundTimes S) (apr float64)

Input 0.01 for 1%.

func ChecksumEthereumAddress

func ChecksumEthereumAddress(addr string) string

Return checksummed ethereum address.

func ConnectArray

func ConnectArray(strList []string, connector string) string

Connect the items in an array with "connector".

func ContainAnyOfStrs

func ContainAnyOfStrs(str string, subStrs []string) bool

func ContainInArray

func ContainInArray[T comparable](target T, array []T) bool

If target contains in array.

func ContainInArrayX added in v0.0.6

func ContainInArrayX(target string, array []string) bool

If target contains in string array, ignore lower or upper.

func CreateKey

func CreateKey() (privateKey string, address string)

Create a pair of private key and address.

func CryptoRandBelow

func CryptoRandBelow(length int) int

Real random/ Crypto random.

func CryptoRandBetween

func CryptoRandBetween(start int, end int, times int) []int

Choose "times" different numbers between "start" and "end".

func FindBytesBetween

func FindBytesBetween(fullBytes []byte, bytesBefore []byte, bytesAfter []byte) (target [][]byte)

Find all []byte between "bytesBefore" and "bytesAfter".

Used to seperate a long []byte into ideal array.

func FindStringBetween

func FindStringBetween(fullStr string, strBefore string, strAfter string) (target []string)

Find all string between "strBefore" and "strAfter".

Used to seperate a long string into ideal array.

func FormatJson

func FormatJson(obj any) string

func FormatJsonByte

func FormatJsonByte(obj any) []byte

func GetMonthStart

func GetMonthStart(location string) time.Time

If location is "" or "UTC", use UTC time.

If location is "Local", use local time.

Location can also be "America/New_York", "Asia/Shanghai", etc.

func GetStringHash

func GetStringHash(input string) string

For example: "TraderJoeSupplyEvent(address,address,uint256,address)".

Space must not be included.

func GetTimeByStr

func GetTimeByStr(str string, location string) time.Time

If location is "" or "UTC", use UTC time.

If location is "Local", use local time.

Location can also be "America/New_York", "Asia/Shanghai", etc.

func GetTimeRangeByType

func GetTimeRangeByType(t string, location string) (start int64, end int64)

If location is "" or "UTC", use UTC time.

If location is "Local", use local time.

Location can also be "America/New_York", "Asia/Shanghai", etc.

func GetTodayStart

func GetTodayStart(location string) time.Time

If location is "" or "UTC", use UTC time.

If location is "Local", use local time.

Location can also be "America/New_York", "Asia/Shanghai", etc.

func GetWeekStart

func GetWeekStart(location string) time.Time

If location is "" or "UTC", use UTC time.

If location is "Local", use local time.

Location can also be "America/New_York", "Asia/Shanghai", etc.

func GetYearStart

func GetYearStart(location string) time.Time

If location is "" or "UTC", use UTC time.

If location is "Local", use local time.

Location can also be "America/New_York", "Asia/Shanghai", etc.

func MathRandBelow

func MathRandBelow(length int) int

Random from timestamp.

func Max added in v0.0.4

func Max[T types.OrderedNumber](x, y T) T

func Min added in v0.0.4

func Min[T types.OrderedNumber](x, y T) T

func PrettifyJson

func PrettifyJson(raw string) string

func PrettyJsonPrintln

func PrettyJsonPrintln(obj any)

func ReadCsv

func ReadCsv(filePath string) ([][]string, error)

Read the csv file.

func ReadJsonSlice

func ReadJsonSlice(path string) ([]string, error)

func RemoveFromArray

func RemoveFromArray[T comparable](array []T, toRemove T) []T

Remove sth from an array and return the new one.

func RemoveFromString

func RemoveFromString(str string, subStr string) string

Remove the first subStr in str.

func RemoveRepetitionInArray

func RemoveRepetitionInArray[T comparable](array []T) []T

Remove repetiton in an array and return the new one.

func Restart

func Restart(functionToRecover func(), functionName string)

Recover from panic and restart.

func RestartAndSleep

func RestartAndSleep(functionToRecover func(), functionName string, sleepTime time.Duration)

Recover from panic and restart after waiting for a while.

func SeperateIntoArray

func SeperateIntoArray(targetStr string, seperateBy string) (res []string)

Seperate a string into an array, the seperater will be deleted.

func SimpleMarshal

func SimpleMarshal(obj any) []byte

func SimpleStringify

func SimpleStringify(obj any) string

func StringToTrueLocations

func StringToTrueLocations(str string) []int64

Consider a map: map[loc]=bool.

Convert the coded string into locations.

func Stringify

func Stringify(obj any) string

func TimeFormat

func TimeFormat(timestamp int64, location string) string

If location is "" or "UTC", use UTC time.

If location is "Local", use local time.

Location can also be "America/New_York", "Asia/Shanghai", etc.

func TimeFormatTime

func TimeFormatTime(timestamp int64, location string) time.Time

If location is "" or "UTC", use UTC time.

If location is "Local", use local time.

Location can also be "America/New_York", "Asia/Shanghai", etc.

func TimeNowString

func TimeNowString() string

func TimestampNow

func TimestampNow() int

func TrueLocationsToString

func TrueLocationsToString(trueLocs []int64) string

Consider a map: map[loc]=bool.

Use a bigInt to locate all true locations and convert into string.

func WriteNewCsv

func WriteNewCsv(filePath string, title []string, text [][]string) error

If file exist, will cover the old file.

func WriteToCsv

func WriteToCsv(filePath string, title []string, text []string) error

Write to csv line by line.

func WriteToCsvResume added in v0.0.6

func WriteToCsvResume(filePath string, title []string, text []string, noRepeatTitle string) error

Write to csv line by line.

Will not write if the value of "noRepeatTitle" already exists.

Types

This section is empty.

Jump to

Keyboard shortcuts

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