tool

package
v0.0.0-...-fc17aaa Latest Latest
Warning

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

Go to latest
Published: May 23, 2023 License: MIT Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// Epoch 2021年3月3号0:00时刻的毫秒级时间戳
	Epoch int64 = 1614700800000
)
View Source
var (
	ErrOutOfMaps = errors.New("位图越界")
)
View Source
var (
	IST, _ = time.LoadLocation("Asia/Kolkata")
)

Functions

func AmountDiv1e12UInt64

func AmountDiv1e12UInt64(amount string, str string) (uint64, bool)

func AmountMul1e12

func AmountMul1e12(amount string, str string) (string, bool)

func Camel2Case

func Camel2Case(name string) string

驼峰式写法转为下划线写法

func Camel2Case2

func Camel2Case2(name string) string

************************************** 其他方法 **************************************

func Case2Camel

func Case2Camel(name string) string

下划线写法转为驼峰写法

func ClickLoginPwdStr

func ClickLoginPwdStr(ss string, str string) bool

ClickLoginPwdStr 校验密码 ss 用户输入密码 str 数据库用户密码

func Explicit

func Explicit(v reflect.Value, depth int)

func FixThPhone

func FixThPhone(phone string) string

func GenUUID

func GenUUID() uint64

GenUUID 生成 UUID

func GenValidateCode

func GenValidateCode(width int) string

func Get16MD5Encode

func Get16MD5Encode(data string) string

func GetBeforeToDayTimeStampRangeByDay

func GetBeforeToDayTimeStampRangeByDay(day int) (int64, int64)

获取当前天n天钱0点时间戳和当天24点时间戳, 传0即为当前天的0点和24点

func GetClientIP

func GetClientIP(req *http.Request) string

func GetFirstDateOfMonth

func GetFirstDateOfMonth(d time.Time) time.Time

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

func GetFirstDateOfWeek

func GetFirstDateOfWeek(now time.Time) time.Time

获取本周周一时间

func GetLastDateOfMonth

func GetLastDateOfMonth(d time.Time) time.Time

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

func GetLoginPwdStr

func GetLoginPwdStr(str string) string

func GetMD5Encode

func GetMD5Encode(data string) string

返回一个32位md5加密后的字符串

func GetSha1Str

func GetSha1Str(str string) string

func GetTimeStampByString

func GetTimeStampByString(str string, loc *time.Location) int64

func GetToDayTimeStampRangeByDay

func GetToDayTimeStampRangeByDay(t time.Time) (int64, int64)

获取当前天的0点和24点

func GetToDayTimeStampRangeByMonth

func GetToDayTimeStampRangeByMonth(t time.Time) (int64, int64)

获取t月第一天0点时间戳和本周最后一天24点时间戳

func GetToDayTimeStampRangeByWeek

func GetToDayTimeStampRangeByWeek(t time.Time) (int64, int64)

获取t周第一天0点时间戳和本周最后一天24点时间戳

func GetVIPLevel

func GetVIPLevel(VIP string) (bool, int)

func GetVIPUpdate

func GetVIPUpdate(VIP string) (bool, int)

func GetZeroTime

func GetZeroTime(d time.Time) time.Time

获取某一天的0点时间

func GetZeroTimeStampToDay

func GetZeroTimeStampToDay() int64

获取当天0点

func Int64ToStr

func Int64ToStr(num int64) string

func Int64ToString

func Int64ToString(num int64) string

func IntInSlice

func IntInSlice(num int, slice []int) (exists bool)

func IntToStr

func IntToStr(num int) string

func IsThPhone

func IsThPhone(phone string) bool

func Lcfirst

func Lcfirst(str string) string

首字母小写

func Print

func Print(str string, data ...interface{})

func QuitSignal

func QuitSignal(quitFunc func())

func RandInt64

func RandInt64(min, max int64) int64

func RandStringRunes

func RandStringRunes(n int) string

func Recover

func Recover()

func RemoveRep

func RemoveRep(slc []int) []int

元素去重

func RemoveRepByLoop

func RemoveRepByLoop(slc []int) []int

通过两重循环过滤重复元素

func RemoveRepByMap

func RemoveRepByMap(slc []int) []int

通过map主键唯一的特性过滤重复元素

func RemoveRepeatedForString

func RemoveRepeatedForString(s []string) []string

通过map键的唯一性去重

func RemoveStringRepeatedByString

func RemoveStringRepeatedByString(slice, repeatedSlice []string) []string

返回第一列表不包含第二个列表内容

func SetMachineID

func SetMachineID(mid int64)

SetMachineID is 设置机器ID

func To2Decimal

func To2Decimal(value float64) float64

取2位精度并转换成int64

func ToYYYYMMDD

func ToYYYYMMDD(t time.Time) int64

func Ucfirst

func Ucfirst(str string) string

首字母大写

func Uint32ToString

func Uint32ToString(num uint32) string

func Uint64ToString

func Uint64ToString(num uint64) string

func WeekByDate

func WeekByDate(t time.Time) int64

判断时间是当年的第几周

Types

type BitMap

type BitMap struct {
	// contains filtered or unexported fields
}

位图

func NewBitMap

func NewBitMap(max uint64) *BitMap

初始化一个BitMap 一个byte有8位,可代表8个数字,取余后加1为存放最大数所需的容量

func (*BitMap) Add

func (b *BitMap) Add(num uint64)

添加一个数字到位图 计算添加数字在数组中的索引index,一个索引可以存放8个数字 计算存放到索引下的第几个位置,一共0-7个位置 原索引下的内容与1左移到指定位置后做或运算

func (*BitMap) IsExist

func (b *BitMap) IsExist(num uint64) bool

判断一个数字是否在位图 找到数字所在的位置,然后做与运算

func (*BitMap) Max

func (b *BitMap) Max() uint64

位图的最大数字

func (*BitMap) Remove

func (b *BitMap) Remove(num uint64)

删除一个数字在位图 找到数字所在的位置取反,然后与索引下的数字做与运算

func (*BitMap) String

func (b *BitMap) String() string

type Bitmap

type Bitmap struct {
	// contains filtered or unexported fields
}

func NewBitmap

func NewBitmap() *Bitmap

func (*Bitmap) Add

func (bitmap *Bitmap) Add(num int)

func (*Bitmap) Has

func (bitmap *Bitmap) Has(num int) bool

func (*Bitmap) Len

func (bitmap *Bitmap) Len() int

func (*Bitmap) String

func (bitmap *Bitmap) String() string

type Buffer

type Buffer struct {
	*bytes.Buffer
}

内嵌bytes.Buffer,支持连写

func NewBuffer

func NewBuffer() *Buffer

func (*Buffer) Append

func (b *Buffer) Append(i interface{}) *Buffer

type Heap

type Heap struct {
	// contains filtered or unexported fields
}

本例为最大堆 最小堆只需要修改less函数即可

func NewHeap

func NewHeap() *Heap

func (*Heap) Pop

func (h *Heap) Pop() *HeapInfo

弹出堆顶的元素,并返回其值

func (*Heap) Push

func (h *Heap) Push(x *HeapInfo)

注意go中所有参数转递都是值传递 所以要让h的变化在函数外也起作用,此处得传指针

func (*Heap) RemoveById

func (h *Heap) RemoveById(id int64) bool

删除堆中位置为i的元素 返回被删元素的值

func (*Heap) RemoveByIndex

func (h *Heap) RemoveByIndex(i int) (*HeapInfo, bool)

删除堆中位置为i的元素 返回被删元素的值

func (*Heap) SetScore

func (h *Heap) SetScore(id, score int64)

修改某个id的分数

type HeapInfo

type HeapInfo struct {
	Id    int64
	Score int64
}

type JsonCamelCase

type JsonCamelCase struct {
	Value interface{}
}

************************************** 驼峰json **************************************

func (JsonCamelCase) MarshalJSON

func (c JsonCamelCase) MarshalJSON() ([]byte, error)

type JsonSnakeCase

type JsonSnakeCase struct {
	Value interface{}
}

************************************** 下划线json **************************************

func (JsonSnakeCase) MarshalJSON

func (c JsonSnakeCase) MarshalJSON() ([]byte, error)

type Maps

type Maps struct {
	*BitMap
	// contains filtered or unexported fields
}

func NewMaps

func NewMaps(width, high uint64) *Maps

func (*Maps) Add

func (m *Maps) Add(x, y, width, high uint64) error

func (*Maps) Remove

func (m *Maps) Remove(x, y, width, high uint64) error

type Switch

type Switch int16

func (Switch) CheckTurnOn

func (s Switch) CheckTurnOn(index int) (result bool)

func (*Switch) TurnOff

func (s *Switch) TurnOff(index int)

func (*Switch) TurnOn

func (s *Switch) TurnOn(index int)

Jump to

Keyboard shortcuts

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