utils

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2024 License: MIT Imports: 35 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// DefaultTrimChars are the characters which are stripped by Trim* functions in default.
	DefaultTrimChars = string([]byte{
		'\t',
		'\v',
		'\n',
		'\r',
		'\f',
		' ',
		0x00,
		0x85,
		0xA0,
	})
)
View Source
var UniqueCodeMap = map[string][]string{
	"0": {"A", "C"},
	"1": {"D", "E"},
	"2": {"F", "G", "Y"},
	"3": {"H", "I"},
	"4": {"Z", "K", "X"},
	"5": {"L", "M", "W"},
	"6": {"N", "O"},
	"7": {"P", "Q", "Z"},
	"8": {"R", "S", "V"},
	"9": {"T", "U"},
}

UniqueCodeMap 用于生成唯一码的映射

Functions

func AddDays added in v0.0.3

func AddDays(t time.Time, days int) time.Time

AddDays 在指定日期上添加天数

func AddHours added in v0.0.3

func AddHours(t time.Time, hours int) time.Time

AddHours 在指定时间上添加小时数

func AddMinutes added in v0.0.3

func AddMinutes(t time.Time, minutes int) time.Time

AddMinutes 在指定时间上添加分钟数

func AddMonths added in v0.0.3

func AddMonths(t time.Time, months int) time.Time

AddMonths 在指定日期上添加月份

func AddSeconds added in v0.0.3

func AddSeconds(t time.Time, seconds int) time.Time

AddSeconds 在指定时间上添加秒数

func AddYears added in v0.0.3

func AddYears(t time.Time, years int) time.Time

AddYears 在指定日期上添加年份

func ArrayToString

func ArrayToString(array []interface{}) string

func CalcDaysFromYearMonth added in v0.0.3

func CalcDaysFromYearMonth(year, month int) int

CalcDaysFromYearMonth 返回给定年份和月份的天数

func CanCallIsNil added in v0.0.3

func CanCallIsNil(v interface{}) bool

CanCallIsNil Can reflect.Value call reflect.Value.IsNil. It can avoid reflect.Value.IsNil panics.

func CompareTime added in v0.0.3

func CompareTime(t1, t2 time.Time) bool

CompareTime 比较两个时间大小

func ConvertToStringSlice added in v0.0.7

func ConvertToStringSlice(data []interface{}) []string

func ConvertToUTC added in v0.0.3

func ConvertToUTC(t time.Time) time.Time

ConvertToUTC 将指定时间转换为UTC时间

func CreateFilePath added in v0.0.3

func CreateFilePath(filePath string) error

CreateFilePath 创建路径

func Decimal added in v0.0.7

func Decimal(value float64) float64

Decimal 保留两位小数

func Decrypt added in v0.0.2

func Decrypt(privateKeyFile, ciphertext string, types string) (plaintext string, err error)

Decrypt 使用私钥解密数据

func DecryptOAEP added in v0.0.2

func DecryptOAEP(privateKeyFile, ciphertext string) (plaintext string, err error)

DecryptOAEP 使用私钥解密数据

func DecryptPKCS1v15 added in v0.0.2

func DecryptPKCS1v15(privateKeyFile, ciphertext string) (plaintext string, err error)

DecryptPKCS1v15 使用私钥解密数据

func DeleteFile added in v0.0.7

func DeleteFile(name string) error

删除文件

func DirSize added in v0.0.7

func DirSize(dirname string) string

DirSize 获取目录下所有文件大小

func DownloadExcel added in v0.0.3

func DownloadExcel(titleList []string, dataList []interface{}, filename ...string) (string, error)

func Encrypt added in v0.0.2

func Encrypt(privateKeyFile, ciphertext string, types string) (plaintext string, err error)

Encrypt 使用公钥加密数据

func EncryptOAEP added in v0.0.2

func EncryptOAEP(publicKeyFile string, content string) (ciphertext string, err error)

EncryptOAEP 使用公钥加密数据

func EncryptPKCS1v15 added in v0.0.2

func EncryptPKCS1v15(publicKeyFile string, content string) (ciphertext string, err error)

EncryptPKCS1v15 使用公钥加密数据

func EncryptPassword added in v0.0.2

func EncryptPassword(password string, salt string) (string, error)

func EncryptString added in v0.0.2

func EncryptString(data string) (encrypt string, err error)

EncryptString encrypts `data` using MD5 algorithms.

func EndTime added in v0.0.3

func EndTime() int64

EndTime 获得今天结束时间戳

func EndTimeByTime added in v0.0.3

func EndTimeByTime(ti int64) int64

EndTimeByTime 获得时间戳对应的23点59分59秒时间戳

func EqualFoldWithoutChars

func EqualFoldWithoutChars(s1, s2 string) bool

EqualFoldWithoutChars checks string `s1` and `s2` equal case-insensitively, with/without chars '-'/'_'/'.'/' '.

func FileSize added in v0.0.7

func FileSize(fileSize int64) string

FileSize 字节的单位转换 保留两位小数

func FormatCmdKey

func FormatCmdKey(s string) string

FormatCmdKey formats string `s` as command key using uniformed format.

func FormatDuration added in v0.0.3

func FormatDuration(d time.Duration) string

FormatDuration 格式化时间间隔

func FormatEnvKey

func FormatEnvKey(s string) string

FormatEnvKey formats string `s` as environment key using uniformed format.

func FormatSize added in v0.0.7

func FormatSize(size int64) string

FormatSize 格式化文件大小。

func FormatTimeRange added in v0.0.3

func FormatTimeRange(start, end time.Time) string

FormatTimeRange 格式化时间范围

func GenerateKeyPair added in v0.0.2

func GenerateKeyPair(bits int, privateKeyFile string, publicKeyFile string) (err error)

GenerateKeyPair 生成RSA密钥对

func GetAgeByBirthday added in v0.0.3

func GetAgeByBirthday(birthday time.Time) int

GetAgeByBirthday 根据生日计算年龄

func GetBeforeDay added in v0.0.3

func GetBeforeDay(year int, month time.Month, day int) int

GetBeforeDay 获得指定日期的前一天的日

func GetBeforeMonth added in v0.0.3

func GetBeforeMonth(year int, month time.Month, day int) time.Month

GetBeforeMonth 获得指定日期的前一天的月

func GetBeforeTime added in v0.0.3

func GetBeforeTime(year int, month time.Month, day int) time.Time

GetBeforeTime 获得指定日期的前一天日期

func GetBeforeWeek added in v0.0.3

func GetBeforeWeek(year int, month time.Month, day int) time.Weekday

GetBeforeWeek 获得指定日期前一天的星期几

func GetBeforeYear added in v0.0.3

func GetBeforeYear(year int, month time.Month, day int) int

GetBeforeYear 获得指定日期的前一天的年

func GetBetweenDates added in v0.0.3

func GetBetweenDates(sdate, edate string) []string

GetBetweenDates 根据开始日期和结束日期计算出时间段内所有日期

func GetCurrentDateString added in v0.0.3

func GetCurrentDateString() string

GetCurrentDateString 获取当前日期字符串

func GetCurrentQuarter added in v0.0.3

func GetCurrentQuarter() int

GetCurrentQuarter 获取当前季度

func GetDay added in v0.0.3

func GetDay() int

GetDay 获得当前时间的天数

func GetDayByTimeInt added in v0.0.3

func GetDayByTimeInt(t int64) int

GetDayByTimeInt 获得指定时间戳的天数

func GetDayByTimeLong added in v0.0.3

func GetDayByTimeLong(t int64) int

GetDayByTimeLong 获得指定时间戳的天数

func GetDayOfYear added in v0.0.3

func GetDayOfYear(t time.Time) int

GetDayOfYear 获取指定日期是所在年份的第几天

func GetDaysInMonth added in v0.0.3

func GetDaysInMonth(year int, month time.Month) int

GetDaysInMonth 获取指定年月的天数

func GetDaysInYear added in v0.0.3

func GetDaysInYear(year int) int

GetDaysInYear 获取指定年份的天数

func GetFirstDateOfMonth added in v0.0.3

func GetFirstDateOfMonth(year int, month time.Month) time.Time

GetFirstDateOfMonth 获取指定年月的第一天

func GetFirstDateOfWeek added in v0.0.3

func GetFirstDateOfWeek(t time.Time) time.Time

GetFirstDateOfWeek 获取指定日期所在周的周一

func GetFirstDayOfNextMonth added in v0.0.3

func GetFirstDayOfNextMonth(t time.Time) time.Time

GetFirstDayOfNextMonth 获取下个月的第一天

func GetHour added in v0.0.3

func GetHour() int

GetHour 获得当前时间的小时数

func GetHourBetweenDates added in v0.0.3

func GetHourBetweenDates(sdate, edate string) []string

GetHourBetweenDates 获取两个日期之间的所有小时

func GetHourByTimeInt added in v0.0.3

func GetHourByTimeInt(t int64) int

GetHourByTimeInt 获得指定时间戳的小时数

func GetHourByTimeLong added in v0.0.3

func GetHourByTimeLong(t int64) int

GetHourByTimeLong 获得指定时间戳的小时数

func GetHourDiffer added in v0.0.3

func GetHourDiffer(startTime, endTime string) float64

GetHourDiffer 计算两个时间差多少小时

func GetLastDateOfMonth added in v0.0.3

func GetLastDateOfMonth(year int, month time.Month) time.Time

GetLastDateOfMonth 获取指定年月的最后一天

func GetLastDateOfWeek added in v0.0.3

func GetLastDateOfWeek(t time.Time) time.Time

GetLastDateOfWeek 获取指定日期所在周的周日

func GetLastDayOfPreviousMonth added in v0.0.3

func GetLastDayOfPreviousMonth(t time.Time) time.Time

GetLastDayOfPreviousMonth 获取上个月的最后一天

func GetLocalIP added in v0.0.7

func GetLocalIP() (string, error)

GetLocalIP 获取服务器内网IP

func GetMicrosecondsFromTime added in v0.0.3

func GetMicrosecondsFromTime(t time.Time) int64

GetMicrosecondsFromTime 获取时间的微秒数

func GetMin added in v0.0.7

func GetMin(a, b int64) int64

GetMin 返回两个整数中的较小值

func GetMinute added in v0.0.3

func GetMinute() int

GetMinute 获得当前时间的分钟数

func GetMinuteByTimeInt added in v0.0.3

func GetMinuteByTimeInt(t int64) int

GetMinuteByTimeInt 获得指定时间戳的分钟数

func GetMinuteByTimeLong added in v0.0.3

func GetMinuteByTimeLong(t int64) int

GetMinuteByTimeLong 获得指定时间戳的分钟数

func GetMinutesDiffer added in v0.0.3

func GetMinutesDiffer(startTime, endTime string) int

GetMinutesDiffer 计算两个时间差多少分钟

func GetMondayTime added in v0.0.3

func GetMondayTime(ti int64) int64

GetMondayTime 获得当前时间戳下的周一的时间戳

func GetMonth added in v0.0.3

func GetMonth() time.Month

GetMonth 获得当前时间的月份

func GetMonthByTimeInt added in v0.0.3

func GetMonthByTimeInt(t int64) time.Month

GetMonthByTimeInt 获得指定时间戳的月份

func GetMonthByTimeLong added in v0.0.3

func GetMonthByTimeLong(t int64) time.Month

GetMonthByTimeLong 获得指定时间戳的月份

func GetMonthFirstDay added in v0.0.3

func GetMonthFirstDay() int64

GetMonthFirstDay 获得当前月份的第一天日期

func GetMonthFirstDayByMonth added in v0.0.3

func GetMonthFirstDayByMonth(year int, month time.Month) int64

GetMonthFirstDayByMonth 获得指定月份的第一天日期

func GetMonthLastDay added in v0.0.3

func GetMonthLastDay() int64

GetMonthLastDay 获得当前月份的最后一天日期

func GetMonthLastDayByMonth added in v0.0.3

func GetMonthLastDayByMonth(year int, month time.Month) int64

GetMonthLastDayByMonth 获得指定月份的最后一天日期

func GetNanosecondsFromTime added in v0.0.3

func GetNanosecondsFromTime(t time.Time) int64

GetNanosecondsFromTime 获取时间的纳秒数

func GetNextWeekday added in v0.0.3

func GetNextWeekday(t time.Time) time.Time

GetNextWeekday 获取下一个工作日

func GetPreviousWeekday added in v0.0.3

func GetPreviousWeekday(t time.Time) time.Time

GetPreviousWeekday 获取上一个工作日

func GetPreviousYearMonth added in v0.0.3

func GetPreviousYearMonth() (int, time.Month)

GetPreviousYearMonth 获得当前日期的上一个年月

func GetPreviousYearMonthBy added in v0.0.3

func GetPreviousYearMonthBy(year int, month time.Month) (int, time.Month)

GetPreviousYearMonthBy 获得指定日期的前一个年月

func GetPublicIP added in v0.0.7

func GetPublicIP() (ip string, err error)

GetPublicIP 获取公网IP

func GetQuarterByMonth added in v0.0.3

func GetQuarterByMonth(month time.Month) int

GetQuarterByMonth 获取指定月份所属的季度

func GetQuarterDay added in v0.0.3

func GetQuarterDay() (start, end string)

GetQuarterDay 获得当前季度的初始和结束日期

func GetQuarterRange added in v0.0.3

func GetQuarterRange(year int, quarter int) (time.Time, time.Time)

GetQuarterRange 获取指定年份和季度的时间范围

func GetRemainingDuration added in v0.0.3

func GetRemainingDuration(t time.Time) time.Duration

GetRemainingDuration 获取距离给定时间的剩余时间

func GetSecond added in v0.0.3

func GetSecond() int

GetSecond 获得当前时间的秒数

func GetSecondByTimeInt added in v0.0.3

func GetSecondByTimeInt(t int64) int

GetSecondByTimeInt 获得指定时间戳的秒数

func GetSecondByTimeLong added in v0.0.3

func GetSecondByTimeLong(t int64) int

GetSecondByTimeLong 获得指定时间戳的秒数

func GetStartQuarter added in v0.0.3

func GetStartQuarter() time.Month

GetStartQuarter 获取每个季度的起始月份

func GetStartQuarterByMonth added in v0.0.3

func GetStartQuarterByMonth(month time.Month) time.Month

GetStartQuarterByMonth 获取指定月份所属季度的起始月份

func GetTime added in v0.0.3

func GetTime(i, types int, begin string) (startTime, endTime string, duration int, unit string)

GetTime 根据类型和开始时间获取时间段及长度

func GetTimeByDay added in v0.0.3

func GetTimeByDay(day int) int64

GetTimeByDay 获得当月指定日期的时间戳

func GetTimeByInt added in v0.0.3

func GetTimeByInt(t int64) time.Time

GetTimeByInt 时间戳转时间

func GetTimeByType added in v0.0.3

func GetTimeByType(types int) (index int, begin, end string)

GetTimeByType 根据类型获取开始时间、结束时间及差值 1 天 2 周 3 月 4 年

func GetTimeFromUnixMilli added in v0.0.3

func GetTimeFromUnixMilli(millis int64) time.Time

GetTimeFromUnixMilli 从毫秒级时间戳获取时间

func GetTimeMills added in v0.0.3

func GetTimeMills(t time.Time) int64

GetTimeMills 转为时间戳(毫秒数)

func GetTimeTagGroup added in v0.0.3

func GetTimeTagGroup() string

GetTimeTagGroup 获取当前日期字符串,结果:2024:05

func GetTimeUnix added in v0.0.3

func GetTimeUnix(t time.Time) int64

GetTimeUnix 转为时间戳(秒数)

func GetTimeWithTimeZone added in v0.0.3

func GetTimeWithTimeZone(t time.Time, zoneName string) (time.Time, error)

GetTimeWithTimeZone 获取指定时区的时间

func GetTimeZone added in v0.0.3

func GetTimeZone() *time.Location

GetTimeZone 获取当前时区

func GetUTCTime added in v0.0.3

func GetUTCTime() time.Time

GetUTCTime 获取UTC时间

func GetUnixMilliFromTime added in v0.0.3

func GetUnixMilliFromTime(t time.Time) int64

GetUnixMilliFromTime 获取时间的毫秒级时间戳

func GetWeek added in v0.0.3

func GetWeek() time.Weekday

GetWeek 获得当前时间的星期几(0-6,0表示星期日)

func GetWeekByTimeInt added in v0.0.3

func GetWeekByTimeInt(t int64) time.Weekday

GetWeekByTimeInt 获得指定时间戳的星期几

func GetWeekByTimeLong added in v0.0.3

func GetWeekByTimeLong(t int64) time.Weekday

GetWeekByTimeLong 获得指定时间戳的星期几

func GetWeekDay added in v0.0.3

func GetWeekDay() (start, end string)

GetWeekDay 获取本周的开始时间和结束时间

func GetWeekOfYear added in v0.0.3

func GetWeekOfYear(t time.Time) int

GetWeekOfYear 获取指定日期是所在年份的第几周

func GetWeekStr added in v0.0.3

func GetWeekStr() string

GetWeekStr 获得周几字符串

func GetWeekStrByWeekInt added in v0.0.3

func GetWeekStrByWeekInt(w int) string

GetWeekStrByWeekInt 获得周几字符串

func GetYear added in v0.0.3

func GetYear() int

GetYear 获得当前时间的年份

func GetYearByTimeInt added in v0.0.3

func GetYearByTimeInt(t int64) int

GetYearByTimeInt 获得指定时间戳的年份

func GetYearByTimeLong added in v0.0.3

func GetYearByTimeLong(t int64) int

GetYearByTimeLong 获得指定时间戳的年份

func GetYesterday added in v0.0.3

func GetYesterday() int

GetYesterday 获取昨天日

func GetYesterdayInt added in v0.0.3

func GetYesterdayInt() int64

GetYesterdayInt 获取昨日时间戳

func Go added in v0.0.3

func Go(fn func() error, errHandler ...ErrHandler)

Go runs the given function in a new goroutine with optional error handling

func InArray added in v0.0.7

func InArray(target string, strArray []string) bool

InArray 判断字符串是否存在数组中

func InArrayInt added in v0.0.7

func InArrayInt(ids []int, id int) bool

func IpInBlackListRange added in v0.0.2

func IpInBlackListRange(ip string, ipList []string) (result bool)

IpInBlackListRange 判断IP是否在黑名单

func IsBase64 added in v0.0.7

func IsBase64(str string) bool

func IsBetween added in v0.0.3

func IsBetween(t, start, end time.Time) bool

IsBetween 判断时间是否在两个时间之间

func IsDebugEnabled

func IsDebugEnabled() bool

IsDebugEnabled checks and returns whether debug mode is enabled. The debug mode is enabled when command argument "gf.debug" or environment "GF_DEBUG" is passed.

func IsEmpty

func IsEmpty(value interface{}) bool

IsEmpty checks whether `value` is empty.

func IsExpired added in v0.0.3

func IsExpired(t time.Time) bool

IsExpired 判断给定时间是否已过期

func IsFloat

func IsFloat(value interface{}) bool

IsFloat checks whether `value` is type of float.

func IsInt

func IsInt(value interface{}) bool

IsInt checks whether `value` is type of int.

func IsJSONString added in v0.0.7

func IsJSONString(content string) bool

IsJSONString 判断是否为JSON

func IsLeapYear added in v0.0.3

func IsLeapYear(year int) bool

IsLeapYear 判断是否为闰年

func IsLetter

func IsLetter(b byte) bool

IsLetter checks whether the given byte b is a letter.

func IsLetterLower

func IsLetterLower(b byte) bool

IsLetterLower checks whether the given byte b is in lower case.

func IsLetterUpper

func IsLetterUpper(b byte) bool

IsLetterUpper checks whether the given byte b is in upper case.

func IsMap

func IsMap(value interface{}) bool

IsMap checks whether `value` is type of map.

func IsNil

func IsNil(value interface{}) bool

IsNil checks whether `value` is nil, especially for interface{} type value.

func IsNumeric

func IsNumeric(s string) bool

IsNumeric checks whether the given string s is numeric. Note that float string like "123.456" is also numeric.

func IsSameDay added in v0.0.3

func IsSameDay(t1, t2 int64) bool

IsSameDay 是否为同一天

func IsSameMinute added in v0.0.3

func IsSameMinute(t1, t2 int64) bool

IsSameMinute 是否为同一分钟

func IsSlice

func IsSlice(value interface{}) bool

IsSlice checks whether `value` is type of slice.

func IsStruct

func IsStruct(value interface{}) bool

IsStruct checks whether `value` is type of struct.

func IsUint

func IsUint(value interface{}) bool

IsUint checks whether `value` is type of uint.

func IsWeekend added in v0.0.3

func IsWeekend(t time.Time) bool

IsWeekend 判断给定时间是否为周末

func MapContainsPossibleKey

func MapContainsPossibleKey(data map[string]interface{}, key string) bool

MapContainsPossibleKey checks if the given `key` is contained in given map `data`. It checks the key ignoring cases and symbols.

Note that this function might be of low performance.

func MapPossibleItemByKey

func MapPossibleItemByKey(data map[string]interface{}, key string) (foundKey string, foundValue interface{})

MapPossibleItemByKey tries to find the possible key-value pair for given key ignoring cases and symbols.

Note that this function might be of low performance.

func Now added in v0.0.3

func Now() string

Now 获得当前时间

func ParseDuration added in v0.0.3

func ParseDuration(s string) (time.Duration, error)

ParseDuration 解析时间间隔字符串

func ParseIpRange added in v0.0.2

func ParseIpRange(cidr string) ([]string, error)

ParseIpRange 用于将以 "," 分割的多个 CIDR 范围字符串解析为 CIDR 数组。 如果一个 CIDR 范围是以 "-" 分割的两个 IP 地址,那么我们会使用 binaryToInt 和 intToIP 函数将它们转换为整数并再次转换为 CIDR 字符串, 并将其加入到 CIDR 数组中。

func ParsePrivateKeyFromPEM added in v0.0.2

func ParsePrivateKeyFromPEM(pemBytes []byte) (privateKey *rsa.PrivateKey, err error)

ParsePrivateKeyFromPEM 从 PEM 格式的字节切片中解析 RSA 私钥

func ParsePublicKeyFromPEM added in v0.0.2

func ParsePublicKeyFromPEM(pemBytes []byte) (publicKey *rsa.PublicKey, err error)

ParsePublicKeyFromPEM 从 PEM 格式的字节切片中解析 RSA 公钥

func Rand added in v0.0.3

func Rand(min, max int) (int, error)

Rand 返回范围 [min, max] 内的随机整数

func RandFloat added in v0.0.3

func RandFloat(min, max float64) (float64, error)

RandFloat 返回范围 [min, max) 内的随机浮点数

func RandIntSlice added in v0.0.3

func RandIntSlice(slice []int) error

RandIntSlice 随机打乱整数切片

func RandLowerString added in v0.0.3

func RandLowerString(length int) (string, error)

RandLowerString 返回指定长度的随机小写字母字符串

func RandNumber added in v0.0.3

func RandNumber(length int) (string, error)

RandNumber 返回指定长度的随机数字字符串

func RandString added in v0.0.3

func RandString(length int) (string, error)

RandString 返回指定长度的随机字符串(包括字母和数字)

func RandStringNoNumber added in v0.0.3

func RandStringNoNumber(length int) (string, error)

RandStringNoNumber 返回指定长度的随机字符串(仅包含字母)

func RandUpperString added in v0.0.3

func RandUpperString(length int) (string, error)

RandUpperString 返回指定长度的随机大写字母字符串

func ReadExcelFile added in v0.0.3

func ReadExcelFile(r *http.Request, tableName ...string) (rows [][]string, err error)

ReadExcelFile 读取EXCEL文件

func RemoveDuplicationMap added in v0.0.7

func RemoveDuplicationMap(arr []string) []string

RemoveDuplicationMap 数组去重

func RemoveRepeatedElementAndEmpty added in v0.0.7

func RemoveRepeatedElementAndEmpty(arr []int) []int

func RemoveSymbols

func RemoveSymbols(s string) string

RemoveSymbols removes all symbols from string and lefts only numbers and letters.

func Replace

func Replace(pattern string, replace, src []byte) ([]byte, error)

Replace replaces all matched `pattern` in bytes `src` with bytes `replace`.

func ReplaceByMap

func ReplaceByMap(origin string, replaces map[string]string) string

ReplaceByMap returns a copy of `origin`, which is replaced by a map in unordered way, case-sensitively.

func ReplaceString

func ReplaceString(pattern, replace, src string) (string, error)

ReplaceString replace all matched `pattern` in string `src` with string `replace`.

func ReplaceTemplate added in v0.0.2

func ReplaceTemplate(content string, variable map[string]interface{}) (result string, err error)

func SavePrivateKeyToFile added in v0.0.2

func SavePrivateKeyToFile(privateKey *rsa.PrivateKey, filename string) (err error)

SavePrivateKeyToFile 将 RSA 私钥保存到文件

func SavePublicKeyToFile added in v0.0.2

func SavePublicKeyToFile(publicKey *rsa.PublicKey, filename string) (err error)

SavePublicKeyToFile 将 RSA 公钥保存到文件

func SetDebugEnabled

func SetDebugEnabled(enabled bool)

SetDebugEnabled enables/disables the internal debug info.

func SetTimeZone added in v0.0.3

func SetTimeZone(name string) error

SetTimeZone 设置时区

func SplitAndTrim

func SplitAndTrim(str, delimiter string, characterMask ...string) []string

SplitAndTrim splits string `str` by a string `delimiter` to an array, and calls Trim to every element of this array. It ignores the elements which are empty after Trim.

func StartAndEndDayTime added in v0.0.3

func StartAndEndDayTime(ti int64) [2]int64

StartAndEndDayTime 获得时间戳对应的起始时间和结束时间

func StartAndEndMonthTime added in v0.0.3

func StartAndEndMonthTime(ti int64) [2]int64

StartAndEndMonthTime 获得指定时间戳的那个月的起始时间和结束时间

func StartAndEndWeekTime added in v0.0.3

func StartAndEndWeekTime(ti int64) [2]int64

StartAndEndWeekTime 获得指定时间戳的周一到周日的时间戳

func StartAndEndYearTime added in v0.0.3

func StartAndEndYearTime(ti int64) [2]int64

StartAndEndYearTime 获得指定时间戳的那年的起始时间和结束时间

func StrToTime added in v0.0.3

func StrToTime(date string) (int64, error)

StrToTime 将字符串转时间戳

func StrToTimeFormat added in v0.0.3

func StrToTimeFormat(date, format string) (int64, error)

StrToTimeFormat 将字符串转时间戳按格式

func StrToTimeFormatByLocal added in v0.0.3

func StrToTimeFormatByLocal(date, format, localName string) (int64, error)

StrToTimeFormatByLocal 将字符串转时间戳按格式和时区

func StripSlashes

func StripSlashes(str string) string

StripSlashes un-quotes a quoted string by AddSlashes.

func StructToMap

func StructToMap(obj interface{}) map[string]interface{}

func Throw added in v0.0.3

func Throw(exception interface{})

Throw throws out an exception, which can be caught be TryCatch or recover.

func Time added in v0.0.3

func Time() int64

Time 获得当前时间戳单位s

func TimeByTime added in v0.0.3

func TimeByTime(t time.Time) int64

TimeByTime 获得时间戳

func TimeFormat added in v0.0.3

func TimeFormat(format string) string

TimeFormat 将当前时间转字符串

func TimeLong added in v0.0.3

func TimeLong() int64

TimeLong 获得当前时间戳到毫秒

func TimeLongToStr added in v0.0.3

func TimeLongToStr(t int64) string

TimeLongToStr 将时间戳转字符串

func TimeToFormat added in v0.0.3

func TimeToFormat(t int64, format string) string

TimeToFormat 将时间戳转字符串并格式化

func TimeToStr added in v0.0.3

func TimeToStr(t int64) string

TimeToStr 将时间戳转字符串

func ToExcel added in v0.0.3

func ToExcel(dataList []interface{}) (content io.ReadSeeker)

ToExcel 生成io.ReadSeeker 参数 titleList 为Excel表头,dataList 为数据

func ToMultiSheetExcel added in v0.0.3

func ToMultiSheetExcel(data map[string][]any) (content io.ReadSeeker)

ToMultiSheetExcel 生成io.ReadSeeker 参数 titleList 为Excel表头,dataList 为数据,data 键为sheet

func Trim

func Trim(str string, characterMask ...string) string

Trim strips whitespace (or other characters) from the beginning and end of a string. The optional parameter `characterMask` specifies the additional stripped characters.

func Try added in v0.0.3

func Try(ctx context.Context, try func(ctx context.Context)) (err error)

Try implements try... logistics using internal panic...recover. It returns error if any exception occurs, or else it returns nil.

func TryCatch added in v0.0.3

func TryCatch(ctx context.Context, try func(ctx context.Context), catch func(ctx context.Context, exception error))

TryCatch implements `try...catch..`. logistics using internal `panic...recover`. It automatically calls function `catch` if any exception occurs and passes the exception as an error. If `catch` is given nil, it ignores the panic from `try` and no panic will throw to parent goroutine.

But, note that, if function `catch` also throws panic, the current goroutine will panic.

func UTCTime added in v0.0.3

func UTCTime() string

UTCTime 获得UTC时间字符串

func UcFirst

func UcFirst(s string) string

UcFirst returns a copy of the string s with the first letter mapped to its upper case.

func UniqueCode added in v0.0.3

func UniqueCode(id int64, minLen int) (string, error)

UniqueCode 根据给定的 ID 和最小长度生成唯一码

func ValidatePassword added in v0.0.7

func ValidatePassword(password string, minimumLength int, requireComplexity int, requireDigit int, requireLowercase int, requireUppercase int) (err error)

func WalkDir added in v0.0.7

func WalkDir(dirname string) ([]fileInfo, error)

WalkDir 获取目录下文件的名称和大小

func ZeroTime added in v0.0.3

func ZeroTime() int64

ZeroTime 获得凌晨零点时间戳

func ZeroTimeByLocal added in v0.0.3

func ZeroTimeByLocal(localName string) (int64, error)

ZeroTimeByLocal 获得指定时区凌晨零点时间戳

func ZeroTimeByTime added in v0.0.3

func ZeroTimeByTime(ti int64) int64

ZeroTimeByTime 获得时间戳对应的凌晨0点时间戳

func ZeroTimeByTimeByLocal added in v0.0.3

func ZeroTimeByTimeByLocal(ti int64, localName string) (int64, error)

ZeroTimeByTimeByLocal 获得时间戳对应的凌晨0点时间戳(指定时区)

Types

type ErrHandler added in v0.0.3

type ErrHandler func(interface{}, []byte)

ErrHandler is a function type for custom error handling

Directories

Path Synopsis
Package empty provides functions for checking empty/nil variables.
Package empty provides functions for checking empty/nil variables.
Package errors provides functionalities to manipulate errors for internal usage purpose.
Package errors provides functionalities to manipulate errors for internal usage purpose.
gcode
Package gcode provides universal error code definition and common error codes implementation.
Package gcode provides universal error code definition and common error codes implementation.
gerror
Package gerror provides rich functionalities to manipulate errors.
Package gerror provides rich functionalities to manipulate errors.
Package grand 提供高性能的随机字节/数字/字符串生成功能。
Package grand 提供高性能的随机字节/数字/字符串生成功能。
Package gstructs provides functions for struct information retrieving.
Package gstructs provides functions for struct information retrieving.
Package ratelimit 提供了一个灵活的令牌桶实现,用于速率限制。
Package ratelimit 提供了一个灵活的令牌桶实现,用于速率限制。
Package reflection provides some reflection functions for internal usage.
Package reflection provides some reflection functions for internal usage.
Package rwmutex provides switch of concurrent safety feature for sync.RWMutex.
Package rwmutex provides switch of concurrent safety feature for sync.RWMutex.
Package gtag providing tag content storing for struct.
Package gtag providing tag content storing for struct.

Jump to

Keyboard shortcuts

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