tool

package
v1.3.2 Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2021 License: Apache-2.0 Imports: 24 Imported by: 1

Documentation

Overview

加密处理

字符串处理

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Base64Decode

func Base64Decode(src string) ([]byte, error)

Base64Decode

func Base64Encode

func Base64Encode(src []byte) string

Base64Encode

func CamelCaseToUnderscore

func CamelCaseToUnderscore(name string) string

驼峰转下划线命名

func Datetime

func Datetime(sec int64, format ...string) string

Datetime 将时间戳转为字符串日期

func DiffDays

func DiffDays(to, from time.Time) int

DiffDays 获取两个时间相隔天数

func ExecCmd

func ExecCmd(dir string, name string, args ...string) (string, error)

执行终端命令

func ExistFolder

func ExistFolder(folder string) bool

ExistDir 检查目录是否存在

func FormatDate

func FormatDate(t time.Time) string

FormatDate 输出time对象的日期字符串

func FormatDatetime

func FormatDatetime(t time.Time) string

FormatDatetime 输出time对象的日期时间字符串

func FormatTime

func FormatTime(t time.Time) string

FormatTime 输出time对象的时间字符串

func GenRandStr

func GenRandStr(length int) (string, error)

GenRandStr 生成随机字符串

func GetCacheName

func GetCacheName(prefix string, tags ...interface{}) string

GetCacheName 生成缓存名称

func GetFirstDateOfMonth

func GetFirstDateOfMonth(d time.Time) time.Time

获取传入的时间所在月份的第一天,即某月第一天的0点。如传入time.Now(), 返回当前月份的第一天0点时间。

func GetHttpRealIP

func GetHttpRealIP(r *http.Request) string

GetHttpRealIP 获取真实IP地址

func GetLastDateOfMonth

func GetLastDateOfMonth(d time.Time) time.Time

获取传入的时间所在月份的最后一天,即某月最后一天的0点。如传入time.Now(), 返回当前月份的最后一天0点时间。

func GetRandom

func GetRandom(min, max int64) int64

GetRandom 在指定范围内生成随机数, min ≤ rnd < max

func GetRandomN

func GetRandomN(min, max, n int64) []int64

GetRandomN 在指定范围内生成N个不重复的随机数 min ≤ rnd ≤ max(如果数据超过10000, 不建议使用)

func GetZeroTime

func GetZeroTime(d time.Time) time.Time

获取某一天的0点时间

func InFloat32Slice

func InFloat32Slice(v float32, sl []float32) bool

InInt64Slice checks given int64 in int64 slice or not.

func InFloat64Slice

func InFloat64Slice(v float64, sl []float64) bool

InInt64Slice checks given int64 in int64 slice or not.

func InInt32Slice

func InInt32Slice(v int32, sl []int32) bool

InInt32Slice checks given int in int slice or not.

func InInt64Slice

func InInt64Slice(v int64, sl []int64) bool

InInt64Slice checks given int64 in int64 slice or not.

func InIntSlice

func InIntSlice(v int, sl []int) bool

InIntSlice checks given int in int slice or not.

func InSlice

func InSlice(v interface{}, slice interface{}) bool

InSlice checks given interface in interface slice.

func InStrSlice

func InStrSlice(v string, sl []string) bool

InStrSlice checks given string in string slice or not.

func InitFolder

func InitFolder(folder string, perm ...os.FileMode) error

func Int32SliceUnique

func Int32SliceUnique(slice []int32) (uniqueslice []int32)

Int32SliceUnique cleans repeated values in slice.

func Int64SliceIface

func Int64SliceIface(slice []int64) (result []interface{})

Int64SliceIface 数字切片转 []interface{}

func Int64SliceUnique

func Int64SliceUnique(slice []int64) (uniqueslice []int64)

Int64SliceUnique cleans repeated values in slice.

func IntSliceIface

func IntSliceIface(slice []int) (result []interface{})

IntSliceIface 数字切片转 []interface{}

func IsSameDay

func IsSameDay(t1, t2 time.Time) bool

IsSameDay 是否同年同月同日

func IsSameMonth

func IsSameMonth(t1, t2 time.Time) bool

IsSameMonth 是否同年同月

func IsSameYear

func IsSameYear(t1, t2 time.Time) bool

IsSameDay 是否同年

func Md5

func Md5(str string) string

MD5 使用MD5对数据签名 (长度32)

func MkFolder

func MkFolder(folder string, perm ...os.FileMode) error

MkFolder 创建目录

func MonthTime

func MonthTime() time.Time

本月起始时间

func RandSlice

func RandSlice(slice interface{})

切片乱序(在原对象的基础上)

func RandomHit

func RandomHit(hit float64, double ...int64) bool

RandomHit 随机命中 (判断百分比概率) hit 是指命中值, 值范围是 0 ~ 1 double 是倍率, 即数值放大多少倍后再判断

func Sha256

func Sha256(str string) string

Sha256 使用Sha256对数据签名 (长度64)

func SliceChunk

func SliceChunk(slice []interface{}, size int) (chunkslice [][]interface{})

SliceChunk separates one slice to some sized slice.

func SliceDiff

func SliceDiff(slice1, slice2 []interface{}) (diffslice []interface{})

SliceDiff returns diff slice of slice1 - slice2.

func SliceFilter

func SliceFilter(slice []interface{}, a filtertype) (ftslice []interface{})

SliceFilter generates a new slice after filter function.

func SliceIntersect

func SliceIntersect(slice1, slice2 []interface{}) (diffslice []interface{})

SliceIntersect returns slice that are present in all the slice1 and slice2.

func SliceMerge

func SliceMerge(slice1, slice2 []interface{}) (c []interface{})

SliceMerge merges interface slices to one slice.

func SlicePad

func SlicePad(slice []interface{}, size int, val interface{}) []interface{}

SlicePad prepends size number of val into slice.

func SliceRand

func SliceRand(a []interface{}) (b interface{})

SliceRand returns random one from slice.

func SliceRandList

func SliceRandList(min, max int) []int

SliceRandList generate an int slice from min to max.

func SliceRandStr

func SliceRandStr(a []string) (b string)

SliceRand returns random one from slice.

func SliceRange

func SliceRange(start, end, step int64) (intslice []int64)

SliceRange generates a new slice from begin to end with step duration of int64 number.

func SliceReduce

func SliceReduce(slice []interface{}, a reducetype) (dslice []interface{})

SliceReduce generates a new slice after parsing every value by reduce function

func SliceShuffle

func SliceShuffle(slice []interface{}) []interface{}

SliceShuffle shuffles a slice.

func SliceShuffleInt

func SliceShuffleInt(slice []int) []int

SliceShuffleInt shuffles a int slice.

func SliceSum

func SliceSum(intslice []int64) (sum int64)

SliceSum sums all values in int64 slice.

func SliceUnique

func SliceUnique(slice []interface{}) (uniqueslice []interface{})

SliceUnique cleans repeated values in slice.

func SplitStrSlice

func SplitStrSlice(str string, sep string) []interface{}

SplitStrSlice 获取字符串切片

func StrSliceIface

func StrSliceIface(slice []string) (result []interface{})

StrSliceIface 字符串切片转 []interface{}

func StrSliceUnique

func StrSliceUnique(slice []string) (uniqueslice []string)

StrSliceUnique cleans repeated values in slice.

func StrToTime

func StrToTime(datetime, format string) (time.Time, error)

StrToTime 将日期字符串转为时间对象

func StrToUnix

func StrToUnix(datetime string, format ...string) int64

StrToUnix 将日期字符串转为时间戳

func StructToByte

func StructToByte(data interface{}) []byte

StructToByte 将结构体转为字节码 取值使用 *(**interface{})(unsafe.Pointer(&bytes)) 方式, 把 interface{} 替换成原结构体类型

func TimeDayBegin

func TimeDayBegin(t time.Time) time.Time

取一天的起始时间(当天的00:00:00)

func TimeDayHour

func TimeDayHour(t time.Time, hour int) time.Time

取一天的特定hour小时的时间(当天的HH:00:00)

func TimeFindWeekDay

func TimeFindWeekDay(t time.Time, whichWeek int, whichWDay time.Weekday) time.Time

取指定月的第X个周Y日期

func TimeFormat

func TimeFormat(t time.Time, format string) string

TimeFormat 格式化时间戳为字符串时间

func TimeMonthBegin

func TimeMonthBegin(t time.Time) time.Time

取一月的起始时间(当月1日)

func TimeMonthEnd

func TimeMonthEnd(t time.Time) time.Time

取当月最后一天(当月1日)

func TimeRFindWeekDay

func TimeRFindWeekDay(t time.Time, whichWeek int, whichWDay time.Weekday) time.Time

取指定月的倒数第X个周Y日期

func TimeToMinute

func TimeToMinute(u int64) int64

时间戳转成剩余多少分钟,结果向上取整

func TimeToStrSlice

func TimeToStrSlice(u int64) []string

时间戳转字符串切片[YYYY,MM,DD,hh,mm,ss]

func TimeUnix

func TimeUnix() int64

TimeUnix 获取当前时区的系统时间戳

func TimeUnixMill

func TimeUnixMill() int64

TimeUnixNano 获取毫秒时间戳

func TimeUnixNano

func TimeUnixNano() int64

TimeUnixNano 获取纳秒时间戳

func TimeWeekBegin

func TimeWeekBegin(t time.Time) time.Time

取一周的起始时间(当周的周一)

func TimeWeekEnd

func TimeWeekEnd(t time.Time) time.Time

func TodayTime

func TodayTime() time.Time

本日起始时间

func UUID

func UUID() string

UUID4 生成唯一ID

func UUID1

func UUID1() string

UUID1 生成唯一ID

func UnderscoreToCamelCase

func UnderscoreToCamelCase(name string) string

下划线转驼峰命名

func UnixToTime

func UnixToTime(sec int64) time.Time

UnixToTime 将时间戳转为time

func Valid

func Valid() *validate

func WeekEndTime

func WeekEndTime() time.Time

本周结束时间

func WeekTime

func WeekTime() time.Time

本周起始时间

Types

type Counter

type Counter struct {
	sync.Mutex
	// contains filtered or unexported fields
}

计数器

func NewCounter

func NewCounter() *Counter

func (*Counter) Add

func (c *Counter) Add(num int64)

func (*Counter) Increment

func (c *Counter) Increment()

func (*Counter) SetStart

func (c *Counter) SetStart(count int64)

设置初始值

func (*Counter) Total

func (c *Counter) Total() int64

type Int32Slice

type Int32Slice []int32

Int32Slice attaches the methods of Interface to []int, sorting in increasing order.

func (Int32Slice) Len

func (p Int32Slice) Len() int

func (Int32Slice) Less

func (p Int32Slice) Less(i, j int) bool

func (Int32Slice) Sort

func (p Int32Slice) Sort()

Sort is a convenience method.

func (Int32Slice) Swap

func (p Int32Slice) Swap(i, j int)

type Int64Slice

type Int64Slice []int64

Int64Slice attaches the methods of Interface to []int, sorting in increasing order.

func (Int64Slice) Len

func (p Int64Slice) Len() int

func (Int64Slice) Less

func (p Int64Slice) Less(i, j int) bool

func (Int64Slice) Sort

func (p Int64Slice) Sort()

Sort is a convenience method.

func (Int64Slice) Swap

func (p Int64Slice) Swap(i, j int)

Jump to

Keyboard shortcuts

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