utils

package
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2024 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AuthWxCode

func AuthWxCode(code string) (rs *response.ResponseCode2Session, err error)

用Code向微信官方换取openid等信息 该函数可能会运行较慢

func Base64Decode

func Base64Decode(str string) string

func Base64Encode

func Base64Encode(str string) string

func CreateFile

func CreateFile(path string) error

创建文件 可能存在跨越目录创建文件的风险

func FileExist

func FileExist(path string) bool

文件是否存在

func Hash

func Hash(str string) string

func InSlice

func InSlice(slice []string, value string) int

判断字符串是否在切片中

func ListToMap

func ListToMap(list interface{}, key string) map[string]interface{}

类似php的array_column($a, null, 'key')

func Mkdir

func Mkdir(path string) error

创建目录

func NumberFormat

func NumberFormat[T ~float32 | ~float64](f T, n ...uint) float64

四舍五入保留小数位

func ReadyFile

func ReadyFile(fileExt ...string) (string, string)

生成文件路径和文件名

func SpreadPeriodToHour

func SpreadPeriodToHour[T timeNumber](start, end T) []T

打散时间段(粒度为1小时) ; 如: "1-4点" 转为 ["1点", "2点", "3点"] 三个时间段

func TimeFormat

func TimeFormat[T timeNumber](t T) string

func Union added in v1.2.0

func Union[T string | Number](slice1, slice2 []T) []T

取两个切片的交集

func UnixGroup

func UnixGroup(times []int) [][]int

时间戳按日期分组; 例: {[1707100000,1707100000], [170720000]}

func WxCheckContent added in v1.0.2

func WxCheckContent(openID, content string) (err error)

检查内容是否合法

Types

type Number

type Number interface {
	~int | ~int8 | ~int16 | ~int32 | ~int64 | ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64
}

Jump to

Keyboard shortcuts

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