utils

package
v0.0.1-202205261838 Latest Latest
Warning

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

Go to latest
Published: May 26, 2022 License: MPL-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BytesToString

func BytesToString(b []byte) string

BytesToString converts byte slice to string without a memory allocation.

func CsvToInt64s

func CsvToInt64s(strValue string) []int64

CsvToInt64s 将逗号分隔的string尝试转换成[1,2,3...]的int64 slice Csv means Comma Separated Value

func GenerateRandString

func GenerateRandString(n int) string

GenerateRandString 生成随机字符串

func GetPagePositions

func GetPagePositions(data interface{}, pageSize int) [][]int

GetPagePositions 获取分页的起始值列表 @return 返回一个二维数组, 第一维是多少页,第二维是每页[]int{start, end} e,g: 假设11个数的列表,分页pageSize是5,那么返回的是:

[]int{
   []int{0, 5},
   []int{5, 10},
   []int{10, 11},
}

func GetSliceData

func GetSliceData(data interface{}) []interface{}

GetSliceData 将传过来的数据转换成[]interface{}

func GetVarName

func GetVarName(myvar interface{}) string

GetVarName 获取变量的名字

func Int64SliceContains

func Int64SliceContains(list []int64, checkItem int64) bool

Int64SliceContains 检查整型slice中是否含有

func Int64sToCsv

func Int64sToCsv(int64s []int64) string

Int64sToCsv 将int64 slice转换成用逗号分隔的字符串: 1,2,3

func IntSliceContains

func IntSliceContains(list []int, checkItem int) bool

IntSliceContains 检查整型slice中是否含有

func IsAlphanumeric

func IsAlphanumeric(s string) bool

IsAlphanumeric check if the string contains only letters and numbers. Empty string is valid.

func IsImageData

func IsImageData(data []byte) bool

IsImageData 是否是图像数据

func IsValidBeginEndTime

func IsValidBeginEndTime(strBeginTime, strEndTime string) error

IsValidBeginEndTime check if it is valid begin/end time

func LogDebug

func LogDebug(msg string, keyvals ...interface{})

func LogError

func LogError(msg string, keyvals ...interface{})

func LogFatal

func LogFatal(msg string, keyvals ...interface{})

func LogWarn

func LogWarn(msg string, keyvals ...interface{})

func ParseArgsWithError

func ParseArgsWithError(keyvals ...interface{}) (error, map[string]interface{})

ParseArgsWithError 将可变参数转换成map, 其中有err关键字返回error @author Ryan Fan @param variadic arguments, key/value键值对,可变参数个数必须为偶数 @return 错误值 @return 除错误值以外的其他参数key->value对

func ParseArgsWithMsgError

func ParseArgsWithMsgError(keyvals ...interface{}) (string, error, map[string]interface{})

ParseArgsWithMsgError 将可变参数转换成map, 其中有err关键字返回error, 有msg关键子返回msg value @author Ryan Fan @param variadic arguments, key/value键值对,可变参数个数必须为偶数 @return 错误值 @return 除错误值以外的其他参数key->value对

func ParseStrTime

func ParseStrTime(value string) (*time.Time, error)

ParseStrTime iso time string转化为时间,layout必须为 "2006-01-02 15:04:05"

func RecordErrorStack

func RecordErrorStack(app string)

RecordErrorStack 将错误信息保存到错误日志文件中

func RemoveInvisibleCharacter

func RemoveInvisibleCharacter(origStr string) string

RemoveInvisibleCharacter 去除掉不能显示的字符

func ReverseInt64Slice

func ReverseInt64Slice(numbers []int64) []int64

ReverseInt64Slice 将[]int64 slice倒序重新排列

func String

func String(value interface{}) (string, error)

String 尝试将值转换成字符串

func StringSliceContains

func StringSliceContains(list []string, checkItem string) bool

StringSliceContains 检查字符串slice中是否含有

func StringToBytes

func StringToBytes(s string) []byte

StringToBytes converts string to byte slice without a memory allocation.

func ToFixed

func ToFixed(num float64, precision int) float64

ToFixed 浮点数到指定小数位

func ToInt64Slice

func ToInt64Slice(strSlice []string) []int64

ToInt64Slice 将string slice转换成[1,2,3...]的int64 slice

func ToStringSlice

func ToStringSlice(int64Slice []int64) []string

ToStringSlice 将int64 slice转换成["1", "2", "3"...]字符串slice

Types

type LogLevel

type LogLevel string
const (
	LogLevelDebug LogLevel = "DBG"
	LogLevelWarn  LogLevel = "WRN"
	LogLevelError LogLevel = "ERR"
	LogLevelFatal LogLevel = "FTL"
)

Directories

Path Synopsis
Package parallel 实现了可优雅关闭退出所有的actors Group | ---> 执行actor | ---> 退出处理 其类似errgroup, 但其不要求actor goroutines去理解上下文的意思,这样它可以在更多的场景下使用.
Package parallel 实现了可优雅关闭退出所有的actors Group | ---> 执行actor | ---> 退出处理 其类似errgroup, 但其不要求actor goroutines去理解上下文的意思,这样它可以在更多的场景下使用.

Jump to

Keyboard shortcuts

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