helpers

package
v0.0.0-...-81db2af Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2025 License: MIT Imports: 48 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// Some default converter types for a nicer syntax
	String  string  = ""
	Bool    bool    = false
	Int     int     = 0
	Float32 float32 = 0
	Float64 float64 = 0
)

These flags define options for tag handling

View Source
const (
	DEFAULT_DATE_FORMAT      = "2006-01-02"
	DEFAULT_TIME_FORMAT      = "2006-01-02 15:04:05"
	TWITTER_DATE_TIME_FORMAT = "2006-01-02T15:04:05.000Z"

	DEFAULT_TIME_ONLY_FORMAT   = "15:04:05"
	DEFAULT_FILTER_TIME_FORMAT = "20060102150405"
)

Variables

View Source
var (
	ErrInvalidCopyDestination        = errors.New("copy destination must be non-nil and addressable")
	ErrInvalidCopyFrom               = errors.New("copy from must be non-nil and addressable")
	ErrMapKeyNotMatch                = errors.New("map's key type doesn't match")
	ErrNotSupported                  = errors.New("not supported")
	ErrFieldNameTagStartNotUpperCase = errors.New("copier field name tag must be start upper case")
)
View Source
var (
	Q128        = big.NewInt(1).Lsh(big.NewInt(1), 128)
	Q96         = big.NewInt(1).Lsh(big.NewInt(1), 96)
	Q32         = big.NewInt(1).Lsh(big.NewInt(1), 32)
	MIN_TICK    = big.NewInt(-887272)
	MAX_TICK    = new(big.Int).Neg(MIN_TICK)
	MAX_UINT256 = new(big.Int).Sub(
		new(big.Int).Exp(big.NewInt(2), big.NewInt(256), nil),
		big.NewInt(1),
	)
)

Functions

func AddressToBinary

func AddressToBinary(address string) ([]byte, error)

func AppendHexStrings

func AppendHexStrings(values ...string) string

func Base64Encode

func Base64Encode(data []byte) string

func BuildUri

func BuildUri(urlString string, queries map[string]string) string

func ContentHtmlByUrl

func ContentHtmlByUrl(link string) string

func ConvertImageDataURL

func ConvertImageDataURL(tokenURL string) string

func ConvertJsonObject

func ConvertJsonObject(jsonStr string, data interface{}) error

func ConvertJsonString

func ConvertJsonString(data interface{}) string

func Copy

func Copy(toValue interface{}, fromValue interface{}) (err error)

Copy copy things

func CopyWithOption

func CopyWithOption(toValue interface{}, fromValue interface{}, opt Option) (err error)

CopyWithOption copy with option

func CrawlUrl

func CrawlUrl(urlToCrawl string) string

func CurlBase64String

func CurlBase64String(apiURL string) (string, error)

func CurlURL

func CurlURL(apiURL string, method string, headers map[string]string, postData interface{}, respData interface{}) error

func CurlURLString

func CurlURLString(apiURL string, method string, headers map[string]string, postData interface{}) (string, error)

func Decrypt

func Decrypt(dataStr, privKey string, result interface{}) error

func ERC20PermitSignature

func ERC20PermitSignature(pk *ecdsa.PrivateKey, domainSeparator, owner, spender common.Address, value, nonce, deadline *big.Int) (byte, [32]byte, [32]byte, error)

get v, r, s variables from eip712 signature for permit function

func Encrypt

func Encrypt(data interface{}, privKey string) (string, error)

func EncryptAndSignAuthToken

func EncryptAndSignAuthToken(authToken AuthToken, serverKey string) (string, error)

func EncryptAuthToken

func EncryptAuthToken(authToken AuthToken, serverKey string) (string, error)

func ExpansionStringArray

func ExpansionStringArray(arr []string) []string

func ExtensionsByContentType

func ExtensionsByContentType(contentType string) (string, error)

func ExtractDomainFromUrl

func ExtractDomainFromUrl(link string) (string, error)

func ExtractEVMAddress

func ExtractEVMAddress(input string) string

func ExtractEtherAddress

func ExtractEtherAddress(content string) string
func ExtractLinks(content string) (string, bool)

func ExtractMapInfoFromOpenAI

func ExtractMapInfoFromOpenAI(content string) map[string]interface{}

func ExtractTweetID

func ExtractTweetID(link string) string

func FormatMoney

func FormatMoney(amount *big.Float) string

func GenShareCode

func GenShareCode(length int) string

func GenerateMD5

func GenerateMD5(v string) string

func GenerateTemplateContent

func GenerateTemplateContent(templateContent string, data interface{}) (string, error)

func GetAmount0ForLiquidity

func GetAmount0ForLiquidity(sqrtRatioAX96, sqrtRatioBX96, liquidity *big.Int) *big.Int

func GetAmount1ForLiquidity

func GetAmount1ForLiquidity(sqrtRatioAX96, sqrtRatioBX96, liquidity *big.Int) *big.Int

func GetAmountsForLiquidity

func GetAmountsForLiquidity(sqrtRatioCurrentX96, sqrtRatioAX96, sqrtRatioBX96, liquidity *big.Int) (*big.Int, *big.Int)

func GetDurationUnit

func GetDurationUnit(unit uint8) string

func GetExternalPrice

func GetExternalPrice(tokenSymbol string) (string, error)

func GetFileExtension

func GetFileExtension(fileName string) string

func GetFrequencyFromMap

func GetFrequencyFromMap(mapInfo map[string]interface{}) int

func GetLiquidityForAmount0

func GetLiquidityForAmount0(sqrtRatioAX96, sqrtRatioBX96, amount0 *big.Int) *big.Int

func GetLiquidityForAmount1

func GetLiquidityForAmount1(sqrtRatioAX96, sqrtRatioBX96, amount1 *big.Int) *big.Int

func GetLiquidityForAmounts

func GetLiquidityForAmounts(sqrtRatioCurrentX96, sqrtRatioAX96, sqrtRatioBX96, amount0, amount1 *big.Int) *big.Int

func GetNextScheduleTime

func GetNextScheduleTime(interval time.Duration, delay time.Duration) *time.Time

func GetNumberFromString

func GetNumberFromString(strText string) int

func GetSignMsg

func GetSignMsg(msg string) string

func GetSqrtRatioAtTick

func GetSqrtRatioAtTick(tick int64) *big.Int

func GetStartDayOfMonth

func GetStartDayOfMonth(t time.Time) time.Time

func GetStartDayOfWeek

func GetStartDayOfWeek(t time.Time) time.Time

func GetStringValueFromMap

func GetStringValueFromMap(mapInfo map[string]interface{}, key string) string

func GetTimeIndex

func GetTimeIndex(blockNumber, txIndex, logIndex uint) uint64

func GetTokenIDFromMap

func GetTokenIDFromMap(mapInfo map[string]interface{}) uint64

func HexToAddress

func HexToAddress(address string) common.Address

func HexToBigInt

func HexToBigInt(s string) *big.Int

func HexToHash

func HexToHash(hashHex string) common.Hash

func HttpRequest

func HttpRequest(fullUrl string, method string, headers map[string]string, reqBody interface{}) ([]byte, *http.Header, int, error)

func HttpRequestFullResponse

func HttpRequestFullResponse(fullUrl string, method string, headers map[string]string, reqBody interface{}) ([]byte, *http.Header, int, error)

func IsValidEthereumAddress

func IsValidEthereumAddress(address string) bool

func JsonRequest

func JsonRequest(fullUrl string, method string, headers map[string]string, reqBody io.Reader) ([]byte, *http.Header, int, error)

func MakeSeoURL

func MakeSeoURL(title string) string

func MergeMetaInfoURL

func MergeMetaInfoURL(baseURL string, mediaURL string) string

func MinifyHTML

func MinifyHTML(html string) (string, error)

func NewDate

func NewDate(day int, month time.Month, year int) *time.Time

func NewDateForDayOfWeek

func NewDateForDayOfWeek(dayOffWeek time.Weekday, month time.Month, year int, number int) *time.Time

func NewLastDateForDayOfWeek

func NewLastDateForDayOfWeek(dayOffWeek time.Weekday, month time.Month, year int) *time.Time

func NewNearbyDayOfMonthAt

func NewNearbyDayOfMonthAt(t *time.Time, dayOffMonth int) *time.Time

func NewNearbyDayOfWeekAt

func NewNearbyDayOfWeekAt(t *time.Time, dayOffWeek time.Weekday) *time.Time

func ParseAddress2Hex

func ParseAddress2Hex(v string) string

func ParseBigInt2Hex

func ParseBigInt2Hex(v *big.Int) string

func ParseGasFeeError

func ParseGasFeeError(errText string) (*big.Int, error)

func ParseHex2Hex

func ParseHex2Hex(v string) string

func ParseNumber2Hex

func ParseNumber2Hex(v string) string

func ParseStringToDateDefault

func ParseStringToDateDefault(value string) *time.Time

func ParseStringToDateTimeDefault

func ParseStringToDateTimeDefault(value string) *time.Time

func ParseStringToDateTimeTwitter

func ParseStringToDateTimeTwitter(value string) *time.Time

func ParseStringToFilterDateDefault

func ParseStringToFilterDateDefault(value string) *time.Time

func ParseStringToTime

func ParseStringToTime(layout string, value string) *time.Time

func ParseTimeToString

func ParseTimeToString(layout string, value *time.Time) string

func ParseTimeToStringDateDefault

func ParseTimeToStringDateDefault(value *time.Time) string

func ParseTimeToStringDateTimeDefault

func ParseTimeToStringDateTimeDefault(value *time.Time) string

func PostThreadTweetByToken

func PostThreadTweetByToken(accessToken string, messages []string) (string, error)

func PostTweetByToken

func PostTweetByToken(accessToken, message string, replyID string) (string, error)

func PostTweetWithMediaByToken

func PostTweetWithMediaByToken(accessToken, message string, mediaID string) (string, error)

func PriceToTick

func PriceToTick(price float64) int64

func QuoteTweetByToken

func QuoteTweetByToken(bearerToken string, content string, quoteTweetId string) (string, error)

func RandHash

func RandHash() string

func RandInArray

func RandInArray(arry []string) string

func RandomBigInt

func RandomBigInt(numBytes int) *big.Int

func RandomFloat

func RandomFloat(from, to float64) float64

func RandomHex

func RandomHex(n int) (string, error)

func RandomInStrings

func RandomInStrings(values []string) string

func RandomInt

func RandomInt(from, to int) int

func RandomNonceNumber

func RandomNonceNumber(numberOfDigits int) (string, error)

func RandomReferralCode

func RandomReferralCode(length int) string

func RandomSeoURLWithLength

func RandomSeoURLWithLength(length int) string

func RandomStringWithLength

func RandomStringWithLength(length int) string

func ReadCSVFromUrl

func ReadCSVFromUrl(url string) ([][]string, error)

func RemoveImageURLs

func RemoveImageURLs(text string) string

func RemoveTrailingHashTag

func RemoveTrailingHashTag(line string) string

func RemoveURLs

func RemoveURLs(text string) string

func ReplaceQuote

func ReplaceQuote(obj string) string

func ReplyTweetByToken

func ReplyTweetByToken(bearerToken string, replyContent string, tweetID, mediaID string) (string, error)

func RepostTweetByToken

func RepostTweetByToken(bearerToken string, userID string, tweetID string) (string, error)

func RodContentHtmlByUrl

func RodContentHtmlByUrl(rawUrl string) string

func Sha256ToNonce

func Sha256ToNonce(s string) *big.Int

func Sign

func Sign(dataStr, privKey string) (string, error)

func SignAuthToken

func SignAuthToken(authTokenStr, privateKey string) (string, error)

func SimpleAddress

func SimpleAddress(hexAddress string) string

func SlackGameAlert

func SlackGameAlert(content string) error

func SlackHook

func SlackHook(slackURL, channel, content string) error

func SliceToStrings

func SliceToStrings(from, len int, getValueAtIndex func(index int) (string, error)) ([]string, error)

func SplitAuthToken

func SplitAuthToken(authToken string) (string, string)

func SplitTextByCharLimit

func SplitTextByCharLimit(text string, limit int) []string

func SplitTextBySentenceAndCharLimitAndRemoveTrailingHashTag

func SplitTextBySentenceAndCharLimitAndRemoveTrailingHashTag(originText string, limit int) []string

SplitTextBySentenceAndCharLimit splits text into lines by sentence boundaries and a character limit per line.

func SubStringBodyResponse

func SubStringBodyResponse(obj string, limit int) string

func TimeAdd

func TimeAdd(t time.Time, d time.Duration) *time.Time

func TimeFromUnix

func TimeFromUnix(n int64) *time.Time

func TimeNow

func TimeNow() *time.Time

func TimeNowAdd

func TimeNowAdd(d time.Duration) *time.Time

func ToWorkHours

func ToWorkHours(t1 *time.Time, t2 *time.Time) float64

func TruncateDate

func TruncateDate(toRound time.Time) time.Time

func TwitterFollowUserCreate

func TwitterFollowUserCreate(accessToken, twitterId string, targetTwitterId string) error

func ValidateMessageSignature

func ValidateMessageSignature(msg string, signatureHex string, signer string) error

func ValidateRecaptcha

func ValidateRecaptcha(secret string, response string) (bool, error)

func VerifyAuthToken

func VerifyAuthToken(authTokenStr, signature, address string) error

func VerifySig

func VerifySig(dataHash []byte, sig64, address string) error

func VerifySignature

func VerifySignature(fromAddress, signatureHex, message string) error

Types

type AllowedCode

type AllowedCode struct {
	Code map[string]string
}

func NewAllowedCode

func NewAllowedCode() AllowedCode

type AuthToken

type AuthToken struct {
	Address   string `json:"address"`
	Exp       int64  `json:"exp"`
	SessionID string `json:"session_id"`
}

func DecryptAndVerifyAuthToken

func DecryptAndVerifyAuthToken(authToken, serverKey string) (*AuthToken, error)

func DecryptAuthToken

func DecryptAuthToken(authTokenStr, serverKey string) (*AuthToken, error)

type BinancePrice

type BinancePrice struct {
	Symbol string `json:"symbol"`
	Price  string `json:"price"`
}

func GetListExternalPrice

func GetListExternalPrice(tokenSymbol string) ([]BinancePrice, error)

type BinancePrice24h

type BinancePrice24h struct {
	Symbol             string `json:"symbol"`
	LastPrice          string `json:"lastPrice"`
	PriceChange        string `json:"priceChange"`
	PriceChangePercent string `json:"priceChangePercent"`
	WeightedAvgPrice   string `json:"weightedAvgPrice"`
	PrevClosePrice     string `json:"prevClosePrice"`
	LastQty            string `json:"lastQty"`
	BidPrice           string `json:"bidPrice"`
	BidQty             string `json:"bidQty"`
	AskQty             string `json:"askQty"`
	OpenPrice          string `json:"openPrice"`
	HighPrice          string `json:"highPrice"`
	LowPrice           string `json:"lowPrice"`
	Volume             string `json:"volume"`
	QuoteVolume        string `json:"quoteVolume"`
	OpenTime           int64  `json:"openTime"`
	CloseTime          int64  `json:"closeTime"`
}

func GetBinancePrice24h

func GetBinancePrice24h(tokenSymbol string) (BinancePrice24h, error)

func GetListExternalPrice24h

func GetListExternalPrice24h(tokenSymbol string) ([]BinancePrice24h, error)

type CoincodexPrice

type CoincodexPrice struct {
	Symbol        string  `json:"symbol"`
	LastPriceUsd  float64 `json:"last_price_usd"`
	DisplaySymbol string  `json:"display_symbol"`
}

//////////

func GetCoincodexPriceByTime

func GetCoincodexPriceByTime(monthStr string) ([]*CoincodexPrice, error)

type FieldNameMapping

type FieldNameMapping struct {
	SrcType interface{}
	DstType interface{}
	Mapping map[string]string
}

type LikedTweetsResponse

type LikedTweetsResponse struct {
	Data []struct {
		ID   string `json:"id"`
		Text string `json:"text"`
	} `json:"data"`
	Meta struct {
		NextToken string `json:"next_token"`
	} `json:"meta"`
}

Response structure for liked tweets

func GetLikedTweets

func GetLikedTweets(userID string, bearerToken string, nextToken string) (*LikedTweetsResponse, error)

Function to fetch liked tweets

type NakaChainPrice

type NakaChainPrice struct {
	Result *struct {
		ETH   string `json:"eth,omitempty"`
		BTC   string `json:"btc,omitempty"`
		EAI   string `json:"eai,omitempty"`
		BVM   string `json:"bvm,omitempty"`
		RUNIX string `json:"runix,omitempty"`
		NAKA  string `json:"naka,omitempty"`
	} `json:"result"`
}

func GetNakaChainMarketPrice

func GetNakaChainMarketPrice() (*NakaChainPrice, error)

type Option

type Option struct {
	// setting this value to true will ignore copying zero values of all the fields, including bools, as well as a
	// struct having all it's fields set to their zero values respectively (see IsZero() in reflect/value.go)
	IgnoreEmpty   bool
	CaseSensitive bool
	DeepCopy      bool
	Converters    []TypeConverter
	// Custom field name mappings to copy values with different names in `fromValue` and `toValue` types.
	// Examples can be found at `TestCustomFieldName`.
	FieldNameMapping []FieldNameMapping
}

Option sets copy options

type RelyError

type RelyError struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
}

type RelyErrorMessage

type RelyErrorMessage struct {
	Code    string      `json:"code"`
	Message *string     `json:"message"`
	Error   interface{} `json:"error"`
}

type TwitterNotification

type TwitterNotification struct {
	Data []struct {
		ID   string `json:"id"`
		Text string `json:"text"`
	} `json:"data"`
}

func GetTwitterNotifications

func GetTwitterNotifications(accessToken, userID string) (*TwitterNotification, error)

type TwitterUserMe

type TwitterUserMe struct {
	Data *struct {
		ID              string `json:"id"`
		Name            string `json:"name"`
		UserName        string `json:"username"`
		CreatedAt       string `json:"created_at"`
		Description     string `json:"description"`
		Location        string `json:"location"`
		PinnedTweetID   string `json:"pinned_tweet_id"`
		ProfileImageURL string `json:"profile_image_url"`
		Protected       bool   `json:"protected"`
		URL             string `json:"url"`
		Verified        bool   `json:"verified"`
	} `json:"data"`
}

func GetTwitterUserMe

func GetTwitterUserMe(accessToken string) (*TwitterUserMe, error)

type TypeConverter

type TypeConverter struct {
	SrcType interface{}
	DstType interface{}
	Fn      func(src interface{}) (dst interface{}, err error)
}

Jump to

Keyboard shortcuts

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