Documentation ¶
Index ¶
- func Apr2Apy(apr any) (apy float64)
- func Apr2ApyWithCompoundTimes[T types.Number](apr any, compoundTimes T) float64
- func Apy2Apr(apy any) (apr float64)
- func Apy2AprWithCompoundTimes[T types.Number](apy any, compoundTimes T) float64
- func Celcius2Fahrenheit[T types.OrderedNumber](degree T) float64
- func ChecksumEthereumAddress(addr string) string
- func ConnectArray(strList []string, connector string) string
- func ContainAnyOfStrs(str string, subStrs []string) bool
- func ContainInArray[T comparable](target T, array []T) bool
- func ContainInArrayX(target string, array []string) bool
- func CreateKey() (privateKey string, address string)
- func CryptoRandBelow[T types.Integer](length T) int
- func CryptoRandBetween(start int, end int, times int) []int
- func Fahrenheit2Celcius[T types.OrderedNumber](degree T) float64
- func FindBytesBetween(fullBytes []byte, bytesBefore []byte, bytesAfter []byte) (target [][]byte)
- func FindStringBetween(fullStr string, strBefore string, strAfter string) (target []string)
- func FormatJson(obj any) string
- func FormatJsonByte(obj any) []byte
- func GetHashAsPriv(input string) (string, string)
- func GetMonthStart(location string) time.Time
- func GetStringHash(input string) string
- func GetTimeByStr(str string, location string) time.Time
- func GetTimeRangeByType(t string, location string) (start int64, end int64)
- func GetTodayStart(location string) time.Time
- func GetWeekStart(location string) time.Time
- func GetYearStart(location string) time.Time
- func LowerFirst(str string) string
- func MathRandBelow[T types.Integer](length T) int
- func Max[T types.OrderedNumber](numbers ...T) T
- func Min[T types.OrderedNumber](numbers ...T) T
- func PrettifyJson(raw string) string
- func PrettyJsonPrintln(obj any)
- func Private2Address(key string) string
- func ReadCsv(filePath string) ([][]string, error)
- func ReadJsonSlice(path string) ([]string, error)
- func RemoveFromArray[T comparable](array []T, toRemove T) []T
- func RemoveFromString(str string, subStr string) string
- func RemoveRepetitionInArray[T comparable](array []T) []T
- func Restart(functionToRecover func(), functionName string)
- func RestartAndSleep(functionToRecover func(), functionName string, sleepTime time.Duration)
- func RunFuncName() string
- func SendMail(sender MailSender, info MailInfo) error
- func SendTelegramSimple(botToken string, chatId int64, text string) error
- func SeperateIntoArray(str string, seperateBy string) (res []string)
- func SimpleMarshal(obj any) []byte
- func SimpleStringify(obj any) string
- func StrCamel2Underline(str string) string
- func StrUnderline2Camel(str string) string
- func StrUnderline2CamelUpperFirst(str string) string
- func StrUnderline2Seperate(str string) string
- func StrUnderline2SeperateTitle(str string) string
- func StringToTrueLocations(str string) []int64
- func Stringify(obj any) string
- func TimeFormat(timestamp int64, location string) string
- func TimeFormatTime(timestamp int64, location string) time.Time
- func TimeNowString() string
- func TimestampNow() int
- func TrueLocationsToString(trueLocs []int64) string
- func UpperFirst(str string) string
- func WriteNewCsv(filePath string, title []string, text [][]string) error
- func WriteToCsv(filePath string, title []string, text []string) error
- func WriteToCsvResume(filePath string, title []string, text []string, noRepeatTitle string) error
- type MailInfo
- type MailSender
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Apr2Apy ¶ added in v0.0.5
Compound times = 365.
Example:
Apr2Apy(0.1) = 0.10515578161622718 // 10% ==> 10.52% Apr2Apy(1) = 1.7145674820220145 // 100% ==> 171.46%
func Apr2ApyWithCompoundTimes ¶ added in v0.0.5
Example:
Apr2ApyWithCompoundTimes(0.1, 100) = 0.10511569772075302 // 10% ==> 10.51% Apr2ApyWithCompoundTimes(1, 100) = 1.704813829421529 // 100% ==> 170.48%
func Apy2Apr ¶ added in v0.0.5
Compound times = 365.
Example:
Apy2Apr(0.1) = 0.09532262476476205 // 10% ==> 9.53% Apy2Apr(1) = 0.693805752190747 // 100% ==> 69.38%
func Apy2AprWithCompoundTimes ¶ added in v0.0.5
Compound times = 365.
Example:
Apy2AprWithCompoundTimes(0.1, 100) = 0.09535561438964724 // 10% ==> 9.54% Apy2AprWithCompoundTimes(1, 100) = 0.6955550056718884 // 100% ==> 69.56%
func Celcius2Fahrenheit ¶ added in v0.0.9
func Celcius2Fahrenheit[T types.OrderedNumber](degree T) float64
func ChecksumEthereumAddress ¶
Return checksummed ethereum address.
func ConnectArray ¶
Connect the items in an array with "connector".
Example:
ConnectArray([]string{"one", "year", "old"}, "-") = "one-year-old"
func ContainAnyOfStrs ¶
Example:
ContainAnyOfStrs("abracadabra", []string{"bra", "tnt"}) = true ContainAnyOfStrs("abracadabra", []string{"abc", "tnt"}) = false
func ContainInArray ¶
func ContainInArray[T comparable](target T, array []T) bool
If target contains in array.
Example:
ContainInArray(1,[]int{1, 2, 3}) = true ContainInArray("", []string{"1", "2", "3"}) = false ContainInArray("0", []string{"1", "2", "3"}) = false
func ContainInArrayX ¶ added in v0.0.6
If target contains in string array, ignore lower or upper.
Example:
ContainInArrayX("aa", []string{"aa", "bb", "cc"}) = true ContainInArrayX("aA", []string{"aa", "bb", "cc"}) = true
func CryptoRandBelow ¶
Real random/ Crypto random.
func CryptoRandBetween ¶
Choose "times" different numbers between "start" and "end".
Example:
CryptoRandBetween(1, 100, 5) = []int{1, 68, 69, 78, 79, 98, 100}
func Fahrenheit2Celcius ¶ added in v0.0.9
func Fahrenheit2Celcius[T types.OrderedNumber](degree T) float64
func FindBytesBetween ¶
Find all []byte between "bytesBefore" and "bytesAfter".
Used to seperate a long []byte into ideal array.
func FindStringBetween ¶
Find all string between "strBefore" and "strAfter".
Used to seperate a long string into ideal array.
Example:
FindStringBetween("aaaaaa", "a", "a") = []string{"", "", ""} FindStringBetween("abcabc", "a", "c") = []string{"b", "b"}
func FormatJson ¶
func FormatJsonByte ¶
func GetHashAsPriv ¶ added in v0.0.9
Get hash and use it as private key, and generate an eth address.
Return hash(private key) and eth address.
Example:
GetHashAsPriv("8") = "0xe4b1702d9298fee62dfeccc57d322a463ad55ca201256d01f62b45b2e1c21c10", "0xe0FC04FA2d34a66B779fd5CEe748268032a146c0"
func GetMonthStart ¶
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 ¶
Get the hash of a string.
Example:
GetStringHash("TraderJoeSupplyEvent(address,address,uint256,address)") = "0x222da511b15d564e69f7e3832eaefbe7fb9875c94fbeecdc358917f0fd0a4f9f"
func GetTimeByStr ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 LowerFirst ¶ added in v0.0.9
The first letter to lower case.
Example:
LowerFirst("Lower") = "lower"
func Max ¶ added in v0.0.4
func Max[T types.OrderedNumber](numbers ...T) T
func Min ¶ added in v0.0.4
func Min[T types.OrderedNumber](numbers ...T) T
func PrettifyJson ¶
func PrettyJsonPrintln ¶
func PrettyJsonPrintln(obj any)
func Private2Address ¶ added in v0.0.9
From private key to address.
func ReadJsonSlice ¶
func RemoveFromArray ¶
func RemoveFromArray[T comparable](array []T, toRemove T) []T
Remove sth from an array and return the new one.
Example:
RemoveFromArray([]string{"aa", "bb"}, "aa") = []string{"bb"} RemoveFromArray([]uint64{1}, 1) = []uint64{}
func RemoveFromString ¶
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.
Example:
RemoveRepetitionInArray([]string{"aa", "bb", "bb", "BB"}) = []string{"aa", "bb", "BB"} RemoveRepetitionInArray([]int{1, 2, 3, 3}) = []int{1, 2, 3}
func Restart ¶
func Restart(functionToRecover func(), functionName string)
Recover from panic and restart.
func RestartAndSleep ¶
Recover from panic and restart after waiting for a while.
func SendMail ¶ added in v0.0.7
func SendMail(sender MailSender, info MailInfo) error
func SendTelegramSimple ¶ added in v0.0.7
Can only send string text.
func SeperateIntoArray ¶
Seperate a string into an array, the seperater will be deleted.
Example:
SeperateIntoArray("one-year-old", "-") = []string{"one", "year", "old"}
func SimpleMarshal ¶
func SimpleStringify ¶
func StrCamel2Underline ¶ added in v0.0.9
Return underline case of str.
Warning: Using both StrUnderline2Camel and StrCamel2Underline (regardless of order) will probably not get the original string!
Example:
StrUnderline2Camel("aBC") = "a_b_c" StrUnderline2Camel("ABC") = "a_b_c"
func StrUnderline2Camel ¶ added in v0.0.9
Return camel case of str. The first letter is lower case.
Warning: Using both StrUnderline2Camel and StrCamel2Underline (regardless of order) will probably not get the original string!
Example:
StrUnderline2Camel("a_b_c") = "aBC"
func StrUnderline2CamelUpperFirst ¶ added in v0.0.9
Return camel case of str. The first letter is upper case.
Warning: Using both StrUnderline2Camel and StrCamel2Underline (regardless of order) will probably not get the original string!
Example:
StrUnderline2Camel("a_b_c") = "ABC"
func StrUnderline2Seperate ¶ added in v0.0.9
Return seperated words of str.
Example:
StrUnderline2Seperate("a_b_c") = "a b c"
func StrUnderline2SeperateTitle ¶ added in v0.0.9
Return title case seperated words of str.
Example:
StrUnderline2SeperateTitle("a_b_c") = "A B C"
func StringToTrueLocations ¶
Consider a map: map[loc]=bool.
Convert the coded string into locations.
Example:
StringToTrueLocations("1432351") = []int64{0, 1, 2, 3, 4, 8, 9, 11, 12, 14, 15, 16, 18, 20}
func TimeFormat ¶
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 ¶
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 ¶
Consider a map: map[loc]=bool.
Use a bigInt to locate all true locations and convert into string.
Example:
TrueLocationsToString([]int64{1, 2, 333, 999}) = "17498005798264095394980017816940970922825355447145699491406164851279623993595007385788105416184430598"
func UpperFirst ¶ added in v0.0.9
The first letter to upper case.
Example:
UpperFirst("upper") = "Upper"
func WriteNewCsv ¶
If file exist, will cover the old file.
func WriteToCsv ¶
Write to csv line by line.
Types ¶
type MailSender ¶ added in v0.0.7
type MailSender struct { Address string `gorm:"column:address" json:"address"` // Sender email address. Nickname string `gorm:"column:nickname" json:"nickname"` // Define sender nickname. Password string `gorm:"column:password" json:"password"` // Mail password or token. Host string `gorm:"column:host" json:"host"` // smtp.xxx.com Port string `gorm:"column:port" json:"port"` // 465 }
Sender info.