utils

package
v1.14.3 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CompareStringSlice

func CompareStringSlice(str1, str2 []string) bool

CompareStringSlice 比较两个 []string

如果完全一致,则返回true,否则返回false

func CompareStringSlicePrefix

func CompareStringSlicePrefix(str, substr []string) bool

CompareStringSlicePrefix 比较两个 []string,判断 str 中每一项是否包含 substr 中的每一项

func FillSlice

func FillSlice[T any](slice []T, length int, fill T) []T

FillSlice 使用指定元素填充 slice 到指定长度

func FindIndex

func FindIndex[T comparable](arr []T, target T) int

FindIndex 返回元素在 slice 中所在的位置

如果未命中,-1

func GetExecutablePath

func GetExecutablePath() string

GetExecutablePath 获取执行文件路径,在 main 包下面调用,能获取到准确地路径

通过判断是否在临时目录,区分 go run 和 go build
go run:
	runtime.Caller(1) 获取调用者的文件路径

go build:
	os.Executable() 获取文件路径

func RandomStr

func RandomStr(length int) string

RandomStr 随机字符串,包含大小写字母、数字、一般字符

字符集:abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890~!@#$%^&*-+

func RandomStrWithSource

func RandomStrWithSource(length int, source string) string

RandomStrWithSource 随机字符串,自行提供字符集

func Reverse added in v1.4.0

func Reverse[T any](arr []T) []T

Reverse 在原slice上进行修改,进行倒序

func UUID

func UUID() string

UUID 封装获取 uuid 的函数

Types

This section is empty.

Jump to

Keyboard shortcuts

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