helper

package
v0.1.58 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2024 License: MIT Imports: 28 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Abs

func Abs(n int64) int64

abs

func Base64Decode

func Base64Decode(content string) string

Base64Decode is base64 decode

func Base64Encode

func Base64Encode(content string) string

Base64Encode is base64 encode

func CleanNewline

func CleanNewline(s string) string

CleanNewline is 清理换行符

func CleanSpecialSymbols

func CleanSpecialSymbols(s string) string

CleanSpecialSymbols is 清理特殊符号

func ClearHTML

func ClearHTML(s string) string

ClearHTML is clear html

func ClearSpace

func ClearSpace(s string) string

ClearSpace is clear space

func ClearTGLink(link string) string

ClearLink 清理URL链接

func CompleteBase64URLSafe

func CompleteBase64URLSafe(s string) string

CompleteBase64URLSafe adjusts a Base64 URL-safe encoded string by replacing '-' with '+', '_' with '/', and adding missing padding '=' characters

func Config

func Config(key string) string

Config is get env var

func DetectGenderFromDict

func DetectGenderFromDict(name string) (string, error)

DetectGenderFromDict

func DetermineGender

func DetermineGender(name string) string

检测一个英文名的性别

func EnsureOwner added in v0.1.1

func EnsureOwner(address, message, signature string) (common.Address, error)

EnsureOwner verifies that the signature corresponds to the given address.

func EscapeHTML

func EscapeHTML(content string) string

EscapeHTML is escape HTML

func FindSubstr

func FindSubstr(content string, params ...any) string

FindSubstr 查找截取

func FormatURL added in v0.1.58

func FormatURL(base string, html string) string

FormatURL 格式化HTML中的URL地址 base: 页面地址 html: html代码 返回处理后的html代码

func GetBotID

func GetBotID(token string) int64

GetBotID is get bot id

func GetBotToken

func GetBotToken(content string) (string, bool)

GetBotToken is get bot token for content

func GetLanguageCode added in v0.1.41

func GetLanguageCode(countryCode string) string

GetLanguageCode 获取国家代码对应的主要语言代码

func GetLinks(s string) []string

GetLinks is get links

func HMAC

func HMAC(h func() hash.Hash, payload []byte, secret []byte) []byte

HMAC is HMAC

func HiddenBotToken

func HiddenBotToken(s string) string

HiddenBotToken is hidden bot token

func IsBotToken

func IsBotToken(token string) bool

IsBotToken is test is bot token

func IsCommand

func IsCommand(text string) bool

IsCommand is check text is command

func IsEnglish

func IsEnglish(str string) bool

检测是否为英文

func IsObjectID

func IsObjectID(v string) bool

IsObjectID is object id

func IsURL

func IsURL(token string) bool

IsURL is test is url

func MD5

func MD5(text string) string

MD5 is md5

func MergeStructs added in v0.1.43

func MergeStructs(dst, src interface{})

MergeStructs 将 src 结构体的非零值字段合并到 dst 结构体中

func NiceNumber

func NiceNumber(num any) string

NiceNumber is nice number

func Number2Icon

func Number2Icon(number int) string

Number2Icon is number to icon

func ParseHumanNum added in v0.1.49

func ParseHumanNum(s string) int64

ParseHumanNum 将人类可读的数字格式(如 "10k"、"10M")转换为实际的整数 如果无法解析,则返回0

func RandDoubleAverage

func RandDoubleAverage(count int64, min float64, max float64) float64

RandDoubleAverage 二倍均值算法生成随机数

func RandFloatRange

func RandFloatRange(min float64, max float64) float64

RandFloatRange

func RandRange

func RandRange(min int, max int) int

RandRange is 随机一个范围

func RandString

func RandString(n int) string

RandString is get rand string

func RunesToHexKey

func RunesToHexKey(runes []rune) string

RunesToHexKey - Convert a slice of runes to hex string representation of their Unicode Code Point value

func Sha1 added in v0.1.15

func Sha1(text string) string

Sha1 is sha1

func SignHash added in v0.1.1

func SignHash(data []byte) []byte

SignHash creates a hash for signing a message.

func Split2Tags

func Split2Tags(text string) []string

Split2Tags is split to tags

func StrLen

func StrLen(text string) int

StrLen is get string length

func StrLimit

func StrLimit(text string, length int) string

StrLimit limits the length of the text to the specified character length

func StringToHexKey

func StringToHexKey(input string) string

StringToHexKey - Convert a string to hex string representation of their Unicode Code Point value

func TimestampToTime added in v0.1.2

func TimestampToTime(msTimestamp int64) time.Time

TimestampToTime 将毫秒级时间戳转换为time.Time类型

func ToBool added in v0.1.50

func ToBool[T Convertible](v T) bool

修改 ToBool 函数

func ToFNV32Hash added in v0.1.48

func ToFNV32Hash[T Convertible](v T) uint32

ToFNV32Hash 泛型函数,使用 FNV-1a 算法将输入转换为 32 位哈希值。

func ToFNV64Hash added in v0.1.48

func ToFNV64Hash[T Convertible](v T) uint64

ToFNV64Hash 泛型函数,使用 FNV-1a 算法将输入转换为 64 位哈希值。

func ToFloat64

func ToFloat64[T Convertible](v T) float64

修改 ToFloat64 函数

func ToInt32 added in v0.1.50

func ToInt32[T Convertible](v T) int32

修改 ToInt32 函数

func ToInt64

func ToInt64[T Convertible](v T) int64

修改 ToInt64 函数

func ToObjectID

func ToObjectID[T Convertible](v T) primitive.ObjectID

ToObjectID 泛型函数,尝试将不同的类型转换为ObjectID。

func ToString

func ToString[T Convertible](v T) string

ToString 泛型函数,尝试将不同的类型转换为string。

func ToUInt32 added in v0.1.34

func ToUInt32[T Convertible](v T) uint32

ToUInt32 泛型函数,尝试将不同的类型转换为uint32。

func ToUInt64 added in v0.1.48

func ToUInt64[T Convertible](v T) uint64

ToUInt64 泛型函数,尝试将不同的类型转换为uint64。

func TrimLastZero

func TrimLastZero(f float64, p ...string) string

TrimLastZero is trim last zero

func UTF8DecodeRune

func UTF8DecodeRune(text string) []string

UTF8DecodeRune is string to Rune

func ValueInSlice

func ValueInSlice[T comparable](v T, slice []T) bool

ValueInSlice 函数检查值v是否存在于切片slice中。 这里使用了泛型,允许对任意可比较的类型进行操作。

Types

type Convertible added in v0.1.48

type Convertible interface {
	~string | ~int | ~int8 | ~int16 | ~int32 | ~int64 |
		~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 |
		~float32 | ~float64 | ~bool | primitive.ObjectID
}

定义一个通用的类型约束

type EqualsConstraint

type EqualsConstraint[T comparable] interface {
}

EqualsConstraint 约束指定了类型T必须能够与自己进行等值比较。

type JSONBody

type JSONBody map[string]any

JSONBody is send message

func MergeJSON

func MergeJSON(map1 JSONBody, maps ...JSONBody) JSONBody

MergeJSON merge json body

func (JSONBody) Error

func (body JSONBody) Error() string

Error

type Zeroer added in v0.1.43

type Zeroer interface {
	IsZero() bool
}

Zeroer 是一个接口,用于自定义零值检查

Jump to

Keyboard shortcuts

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