cyutil

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2025 License: MIT Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	PUB_VALUE = "Cyclone890123456"
	IV        = "1234567890123456"
)
View Source
var ToString = ToStr

Functions

func Base64Decode

func Base64Decode(v string) string

func Base64Encode

func Base64Encode(v string) string

func Diff

func Diff(oldDatas, newDatas []map[string]interface{}, key string) (newData, updateData, delData []map[string]interface{})

func FormatDuration

func FormatDuration(d time.Duration) (r string)

FormatDuration formats a time.Duration into a human-readable string with appropriate units (ns, µs, ms, s) based on the duration's magnitude. This is useful for logging request latencies in a more readable format.

func FromJson

func FromJson[T any](b string) (*T, error)

func GenHMAC

func GenHMAC(data string, key string) string

GenHMAC generates an HMAC-SHA1 signature and encodes it as Base64

func GetBool

func GetBool(m map[string]interface{}, key string, igoreCase ...bool) bool

func GetFloat

func GetFloat(m map[string]interface{}, key string, igoreCase ...bool) float64

func GetInt

func GetInt(m map[string]interface{}, key string, igoreCase ...bool) int

func GetInt64

func GetInt64(m map[string]interface{}, key string, igoreCase ...bool) int64

func GetSignature

func GetSignature(method, key string, queryParam map[string]string) string

GetSignature generates a signature for API requests method: HTTP method (GET, POST, etc.) key: Secret key for signing queryParam: Map of query parameters

func GetSignatureFromURL

func GetSignatureFromURL(method, key, url string) (string, error)

GetSignatureFromURL generates a signature from a URL string method: HTTP method (GET, POST, etc.) key: Secret key for signing url: Full URL including query parameters

func GetStr

func GetStr(m map[string]interface{}, key string, igoreCase ...bool) string

func GetVal

func GetVal[T any](m map[string]interface{}, key string, igoreCase ...bool) T

func GetValue

func GetValue(m map[string]interface{}, keys []string, ignoreCase ...bool) (interface{}, error)

func GraphSort

func GraphSort(names []string, depGraph map[string]map[string]struct{}) ([]string, error)

func HashInt

func HashInt(input string) uint32

func IsDigits

func IsDigits(s string) bool

func MD5

func MD5(params ...interface{}) string

func MapToStruct

func MapToStruct[T any](m map[string]interface{}, tag ...string) (*T, error)

func MergeMaps

func MergeMaps(m1 ...map[string]interface{}) map[string]interface{}

func MyStringToTimeHook

func MyStringToTimeHook() mapstructure.DecodeHookFunc

func NanoID

func NanoID(l ...int) string

func NewObj

func NewObj[T any]() (T, bool)

func PadStart

func PadStart(s string, length int, pad string) string

func ParseQueryToMap

func ParseQueryToMap(queryString string) (map[string]string, error)

ParseQueryToMap converts a query string to a map of parameters

func ParseURLParams

func ParseURLParams(url string) (string, map[string]string, error)

ParseURLParams parses URL parameters into a map

func ParseUserAgent

func ParseUserAgent(ua string) string

ParseUserAgent extracts OS and browser information from a user agent string Returns a simplified string with OS type/version and browser type/version

func Ptr

func Ptr[T any](v T) *T

func RealVal

func RealVal(encodeVal string) string

func RemoveSqlComments

func RemoveSqlComments(line string, inMultiLineComment bool) (processedLine string, stillInComment bool)

func ReplaceSqlStringContent

func ReplaceSqlStringContent(line string, expectedEnd string, vPlaceholder ...string) (processedLine string, nextExpectedEnd string)

func SM4Decode2

func SM4Decode2(v string) string

func SM4Decrypt2

func SM4Decrypt2(key, iv, cipherText []byte) ([]byte, error)

func SetValue

func SetValue(m map[string]interface{}, keys []string, value interface{}) (map[string]interface{}, error)

func SliceMapToSliceStruct

func SliceMapToSliceStruct[T any](m []map[string]interface{}, tag ...string) ([]*T, error)

func SliceToAny

func SliceToAny[T any](s []T) []any

func SnowflakeID

func SnowflakeID() string

func SortParam

func SortParam(method string, params map[string]string) string

SortParam creates a normalized string from parameters following RFC3986 rules

func StructToMap

func StructToMap[T any](o *T, tag ...string) (map[string]interface{}, error)

func ToBool

func ToBool(value interface{}) bool

func ToFloat64

func ToFloat64(value interface{}) float64

func ToInt

func ToInt(value interface{}) int

func ToInt64

func ToInt64(value interface{}) int64

func ToJson

func ToJson[T any](d T) (string, error)

func ToStr

func ToStr(value interface{}) string

func ToTimestamp

func ToTimestamp(tm time.Time) int64

func TravelMap

func TravelMap(m map[string]any, f func(k string, v any) error) error

func TraverseString

func TraverseString(s string, separatorChars string, callback CallbackFunc) error

traverseString tokenizes a string and calls a callback for each word found.

func UUID

func UUID() string

func WalkMapLeaves

func WalkMapLeaves(root map[string]any, f func(path string, v any) error) error

func XID

func XID() string

Types

type CallbackFunc

type CallbackFunc func(w *WordInfo) error

type DelimiterInfo

type DelimiterInfo struct {
	S string // 分隔符的内容
	P int    // 分隔符在原字符串中的起始位置(索引)
}

DelimiterInfo 用于存储找到的分隔符信息

func FindDelimiters

func FindDelimiters(str, sep string) []DelimiterInfo

FindDelimiters 查找字符串 str 中所有由 sep 组成的连续分隔符 返回包含分隔符内容和起始位置的 DelimiterInfo 切片

type WordInfo

type WordInfo struct {
	Word      string
	Pos       int
	Separator string
	Index     int
}

Jump to

Keyboard shortcuts

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