utils

package
v0.0.0-...-1dedb3c Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2024 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddSlashes

func AddSlashes(str string) string

AddSlashes 转义

func ArrayColumn

func ArrayColumn[M ~[]map[K]V, K comparable, V any](m M, key K) []V

func ArrayDiff

func ArrayDiff[V comparable](array1 []V, arrayOthers ...[]V) []V

func ArrayIn

func ArrayIn[V comparable](needle V, haystack []V) bool

func ArrayIntersect

func ArrayIntersect[V comparable](array1 []V, arrayOthers ...[]V) []V

func ArrayKey

func ArrayKey[M ~map[K]V, K comparable, V any](m M) []K

func ArraySearch

func ArraySearch[V comparable](needle V, haystack []V) int

func ArrayUnique

func ArrayUnique[V comparable](idList []V) []V

func ArrayUnset

func ArrayUnset[V comparable](s []V, elems ...V) []V

func ArrayValue

func ArrayValue[M ~map[K]V, K comparable, V any](m M, sort ...K) []V

func CheckFreq

func CheckFreq(r *redis.Redis, optionList []FrequencyOption) (bool, error)

CheckFreq 频次校验通用 业务校验使用 高并发不支持

func CheckTicket

func CheckTicket(r *redis.Redis, from string, biz string, ticket string) (bool, error)

func Crc32

func Crc32(s string) uint32

func ExtractUrlsFromHtml

func ExtractUrlsFromHtml(content string) []string

func FormatRelativeTime

func FormatRelativeTime(showDate time.Time) string

FormatRelativeTime 转换为相对时间

func GenRandomNumStr

func GenRandomNumStr(n int) string

GenRandomNumStr 生成随机数字字符串

func GenRandomStr

func GenRandomStr(n int) string

func GenUniqId

func GenUniqId(prefix string) string

GenUniqId 生成唯一字符串

func GetCacheExpWithRand

func GetCacheExpWithRand(t time.Duration) time.Duration

GetCacheExpWithRand 返回 t的时间 + [0- t的时间一半的时间)

func GetCacheKey

func GetCacheKey(key string, args ...any) string

GetCacheKey 格式化key

func MapToUrlQueryString

func MapToUrlQueryString[V comparable](data map[string]V) string

MapToUrlQueryString 将map格式数据拼接成url Get方式参数【注:拼接后的参数顺序是随机的】

func Md5

func Md5(s string) string

func ParseTimeFromString

func ParseTimeFromString(tm string) time.Time

ParseTimeFromString 解析时间

func SetFreq

func SetFreq(r *redis.Redis, optionList []FrequencyOption) (bool, error)

func SetOnceTicketKey

func SetOnceTicketKey(key string)

func SetTicket

func SetTicket(r *redis.Redis, from string, biz string, second int, ticket string) (string, error)

SetTicket 一次性ticket通用

func Sha256

func Sha256(s, salt string) string

func SpanIDFromContext

func SpanIDFromContext(ctx context.Context) string

func StripSlashes

func StripSlashes(str string) string

StripSlashes 去除转义

func StripTags

func StripTags(data string, allowedTags []string) string

StripTags 去除html标签

func Substr

func Substr(str string, start int, length int) string

Substr 截取字符

func TraceIDFromContext

func TraceIDFromContext(ctx context.Context) string

func XorDecrypt

func XorDecrypt(encryptedBase64 string, key string) (string, error)

XorDecrypt XOR 使用给定密钥对Base64编码后的加密字符串进行解密

func XorEncrypt

func XorEncrypt(input, key string) string

XorEncrypt XOR 对给定字符串使用给定密钥进行加密或解密,并返回Base64编码后的字符串

Types

type FrequencyOption

type FrequencyOption struct {
	Key    string `json:"key"`
	Second int    `json:"second"`
	Cnt    int    `json:"int"`
	Msg    string `json:"msg"`
}

Jump to

Keyboard shortcuts

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