common

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2022 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

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 ContainInArray

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

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 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

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

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

func Min

func Min[T 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)

filePath e.g. "./example.csv"

func ReadJsonSlice

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

func RemoveRepetitionInArray

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

func Restart

func Restart(functionToRecover func(), functionName string)

recover from panic and wait for a while

func SendTelegram

func SendTelegram(botToken string, chatId int64, text ...any) error

func SimpleMarshal

func SimpleMarshal(obj any) []byte

func SimpleStringify

func SimpleStringify(obj any) string

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 ToAddress

func ToAddress(input any) common_eth.Address

func ToBigInt

func ToBigInt(input any) *big.Int

func ToDecimal

func ToDecimal(input any) decimal.Decimal

func ToFloat64

func ToFloat64(input any) float64

func ToInt

func ToInt(input any) int

func ToInt64

func ToInt64(input any) int64

func ToLowerString

func ToLowerString(input any) string

func ToString

func ToString(input any) string

func WriteNewCsv

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

if exist, will cover the old file

func WriteToCsv

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

write to csv line by line

Types

type AddressTypes

type AddressTypes interface {
	string | common_eth.Address
}

type BigNumber

type BigNumber interface {
	~*big.Int | ~*big.Float
}

type Float

type Float interface {
	~float32 | ~float64
}

type Integer

type Integer interface {
	Signed | Unsigned
}

type Number

type Number interface {
	OrderedNumber | BigNumber
}

type Ordered

type Ordered interface {
	OrderedNumber | ~string
}

partially order sets

type OrderedNumber

type OrderedNumber interface {
	Integer | Float
}

type RobotAdapter

type RobotAdapter struct {
	TeleBot *tgbotapi.BotAPI
}

func NewBot

func NewBot(token string) (RobotAdapter, error)

func (*RobotAdapter) SendTelegram

func (r *RobotAdapter) SendTelegram(chat_id int64, v ...any)

send telegram

type Signed

type Signed interface {
	~int | ~int8 | ~int16 | ~int32 | ~int64
}

type Unsigned

type Unsigned interface {
	~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr
}

Jump to

Keyboard shortcuts

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