utils

package
v1.0.37 Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2023 License: MPL-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	EmptyJsonArray  = StringToBytes("[]")
	EmptyJsonObject = StringToBytes("{}")
)
View Source
var (
	DEFAULT_TIME_LOCATION = time.FixedZone("CST", 8*3600)
	ISO_DATE_TEMPLATE     = "2006-01-02"
)

Functions

func AlphaNumeric

func AlphaNumeric(s string) string

AlphaNumeric 去除字符数字以外的所有字符

func BytesToString

func BytesToString(b []byte) string

BytesToString converts byte slice to string without a memory allocation.

func Chinese

func Chinese(s string) string

Chinese 去除中文以外的所有字符

func CleanString

func CleanString(origStr string, args ...bool) string

CleanString 处理字符串, args[0]为是否转换为小写

func Contains

func Contains[T comparable](list []T, checkItem T) bool

func CsvToInt32s

func CsvToInt32s(strValue string) []int32

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

func CsvToInt64s

func CsvToInt64s(strValue string) []int64

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

func DeltaDays

func DeltaDays(t1, t2 time.Time) int

DeltaDays 计算两个日期间的间隔天数

func FromUnixTime

func FromUnixTime(ts int64, format string) string

func GenerateRandString

func GenerateRandString(n int) string

GenerateRandString 生成随机字符串

func Get1stDayOfWeek

func Get1stDayOfWeek() string

Get1stDayOfWeek 获取本周第一天

func GetBeginUnixTS

func GetBeginUnixTS(beginDate string) int64

GetBeginUnixTS 给出字符串的日期,例如2006-01或者2006-01-02, 返回对应的时间戳

func GetBetweenDays

func GetBetweenDays(format, beginDate string, args ...string) ([]string, error)

GetBetweenDays @description 获取开始日期和结束日期中间的所有日期列表 @param beginDate string 开始时间,格式为:2020-04-01 @param args ...string 如果指定了结束时间,则用结束时间,否则用当前时间,格式为:2020-04-01 @return 在这段日期时间内的所有天包含起始日期 []string,如:[2020-04-01 2020-04-02 2020-04-03]

func GetDayBeginTimeSince

func GetDayBeginTimeSince(ts int64, ndays int) time.Time

GetDayBeginTimeSince 获取从某个时间n天后第一秒的时间, 指定时间之前的日期00:00:00时间戳 ndays: -1表示前一天,0表示今天,1表示后一天

func GetDayEndTime

func GetDayEndTime(ndays int) time.Time

GetDayEndDate 获取当前时间n天后最后一秒的时间, 当前时间后n天后的日期23:59:59时间戳 ndays: -1表示前一天,0表示今天,1表示后一天

func GetDayEndTimeSince

func GetDayEndTimeSince(ts int64, ndays int) time.Time

GetDayEndTimeSince 获取从某个时间n天后最后一秒的时间, 指定时间之前的日期23:59:59时间戳 ndays: -1表示前一天,0表示今天,1表示后一天

func GetEndUnixTS

func GetEndUnixTS(endDate string) int64

func GetFuncName

func GetFuncName(fn any) string

GetFuncName 从函数实例获取函数名

func GetMonthBeginTime

func GetMonthBeginTime(nmonth int) time.Time

GetMonthBeginTime 获取当前时间所在月份指定月份的第一天的开始时间, 即某月第一天的0点 如果nmonth=-1, 则是上一个月的第一天的00:00:00, 如果nmonth=0, 则是本月的第一天的00:00:00 如果nmonth=1, 则是下个月的第一天的00:00:00

func GetMonthBeginTimeSince

func GetMonthBeginTimeSince(ts int64, nmonth int) time.Time

GetMonthEndTimeSince 获取从某个时间n个月后第一天第一秒的时间 nmonth: -1表示前一个月,0表示本月,1表示后一个月

func GetMonthEndTime

func GetMonthEndTime(nmonth int) time.Time

GetMonthEndTime 获取当前时间的指定月份的最后一天的23:59:59 即某月最后一天的23:59:59 如果nmonth=-1, 则是上一个月的最后一天的23:59:59 如果nmonth=0, 则是本月的最后一天的23:59:59 如果nmonth=1, 则是下个月的最后一天的23:59:59

func GetMonthEndTimeSince

func GetMonthEndTimeSince(ts int64, nmonth int) time.Time

GetMonthEndTimeSince 获取从某个时间n个月最后一天最后一秒的时间, 指定时间之前的日期23:59:59时间戳 nmonth: -1表示前一个月,0表示本月,1表示后一个月

func GetNeo4jPathPattern

func GetNeo4jPathPattern(args ...int32) string

GetNeo4jPathPattern 解析Neo4j语法的Variable-length pattern

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 GetStructName

func GetStructName(myvar interface{}) string

func GetVarName

func GetVarName(myvar interface{}) string

GetVarName 获取变量的名字

func GetYearBeginTime

func GetYearBeginTime(nyear int) time.Time

GetYearBeginTime 获取当前时间所在年份指定年的第一天的开始时间, 即某年第一天的0点 如果nyear=-1, 则是上一年的第一天的00:00:00, 如果nyear=0, 则是本年的第一天的00:00:00 如果nyear=1, 则是下一年的第一天的00:00:00

func GetYearEndTime

func GetYearEndTime(nyear int) time.Time

GetYearEndTime 获取当前时间的指定年份的最后一天的23:59:59 即某年最后一天的23:59:59 如果nyear=-1, 则是上一个年的最后一天的23:59:59 如果nyear=0, 则是本年的最后一天的23:59:59 如果nyear=1, 则是下一年的最后一天的23:59:59

func Int32sToCsv

func Int32sToCsv(int32s []int32) string

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

func Int64sToCsv

func Int64sToCsv(int64s []int64) string

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

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 IsNumeric

func IsNumeric(s string) bool

IsNumeric check if the string contains only numbers. Empty string is valid.

func IsValidBeginEndTime

func IsValidBeginEndTime(strBeginTime, strEndTime string) error

IsValidBeginEndTime check if it is valid begin/end time

func JsonArray

func JsonArray(args ...any) []byte

JsonArray 将slice转换成[]byte数据,如果slice为nil或空则返回空json array bytes

func JsonObject

func JsonObject(args ...any) []byte

JsonObject 将object转换成[]byte数据,如果object为nil或空则返回空json object bytes

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 Numeric

func Numeric(s string) string

Numeric 去除数字以外的所有字符

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 StringToBytes

func StringToBytes(s string) []byte

StringToBytes converts string to byte slice without a memory allocation.

func ToBytes

func ToBytes(value interface{}) ([]byte, error)

func ToFixed

func ToFixed(num float64, precision int) float64

ToFixed 浮点数到指定小数位

func ToInt32Slice

func ToInt32Slice(strSlice []string) []int32

ToInt32Slice 将string slice转换成[1,2,3...]的int32 slice

func ToInt64Slice

func ToInt64Slice(strSlice []string) []int64

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

func ToString

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

ToString 尝试将值转换成字符串

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
Package parallel 实现了可优雅关闭退出所有的actors Group

Jump to

Keyboard shortcuts

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