utils

package
v0.5.3 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2026 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ByteToStringView added in v0.5.3

func ByteToStringView(b []byte, maxLen int) string

func Bytes2Size

func Bytes2Size(num int64) string

func Contains

func Contains[T comparable](value T, slice []T) bool

func ContainsString

func ContainsString(s string, keywords []string) bool

func Decimal

func Decimal(value float64, decimalPlace int) float64

func DifferenceSets

func DifferenceSets[T comparable](set1, set2 map[T]bool) (diff1, diff2 []T)

func EscapeMarkdownText

func EscapeMarkdownText(text string) string

func Filter

func Filter[T any](arr []T, f func(T) bool) []T

func GenerateKey

func GenerateKey() string

func GenerateTradeNo

func GenerateTradeNo() string

func GetGinValue

func GetGinValue[T any](c *gin.Context, key string) (T, bool)

func GetIp

func GetIp() (ip string)

func GetLocalTimezone

func GetLocalTimezone() string

func GetModelsWithMatch

func GetModelsWithMatch(modelList *[]string, modelName string) string

func GetOrDefault

func GetOrDefault[T any](env string, defaultValue T) T

func GetPointer

func GetPointer[T any](val T) *T

func GetRandomInt

func GetRandomInt(length int) int

func GetRandomString

func GetRandomString(length int) string

func GetTimeString

func GetTimeString() string

func GetTimestamp

func GetTimestamp() int64

func GetUUID

func GetUUID() string

func GetUnixTime

func GetUnixTime() int64

func IntMax

func IntMax(a int, b int) int

func Interface2String

func Interface2String(inter interface{}) string

func IsFileExist

func IsFileExist(path string) bool

func IsIpInCidr

func IsIpInCidr(ip string, cidr string) bool

IsIpInCidr 判断IP是否在CIDR范围内

func Marshal

func Marshal[T interface{}](data T) string

func Max

func Max(a int, b int) int

func MessageWithRequestId

func MessageWithRequestId(message string, id string) string

func NumClamp

func NumClamp(value, minVal, maxVal float64) float64

func OpenBrowser

func OpenBrowser(url string)

func ProxyFunc

func ProxyFunc(req *http.Request) (*url.URL, error)

func RequestBuilder

func RequestBuilder(
	ctx context.Context,
	method string,
	url string,
	body any,
	header http.Header,
) (req *http.Request, err error)

func Seconds2Time

func Seconds2Time(num int) (time string)

func SetProxy

func SetProxy(proxyAddr string, ctx context.Context) context.Context

func SliceToMap

func SliceToMap[T comparable](slice []T) map[T]bool

func Socks5ProxyFunc

func Socks5ProxyFunc(ctx context.Context, network, addr string) (net.Conn, error)

func String2Int

func String2Int(str string) int

func String2Int64

func String2Int64(str string) int64

func UnescapeHTML

func UnescapeHTML(x string) interface{}

func UnmarshalString

func UnmarshalString[T interface{}](data string) (form T, err error)

Types

type ContextKey

type ContextKey string
const ProxyAddrKey ContextKey = "proxyAddr"
const ProxyHTTPAddrKey ContextKey = "proxyHttpAddr"
const ProxySock5AddrKey ContextKey = "proxySock5Addr"

Jump to

Keyboard shortcuts

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