utils

package
v0.0.0-...-f82ef47 Latest Latest
Warning

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

Go to latest
Published: May 16, 2021 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Crypto *crypto
View Source
var ErrorTimeout = errors.New("timeout")
View Source
var EventWriteChanSize = 5000
View Source
var Random *random
View Source
var WeekStartDay = 1

每周开始时间 1:周一,0:周日

View Source
var WorkerWriteChanSize = 5000

Functions

func GetDayTime

func GetDayTime(t time.Time, addDays int) time.Time

获取一天的开始时间 addDays:天偏移,0:今天凌晨,1:明天凌晨

func GetSignFromStamp

func GetSignFromStamp(s int64) int32

通过时间戳获取SIGN

func GetSignFromTime

func GetSignFromTime(t time.Time) int32

func GetTimeFromSign

func GetTimeFromSign(sign int32) time.Time

func GetWeekTime

func GetWeekTime(t time.Time, addWeeks int) time.Time

获取本周开始时间 addWeeks:周偏移,0:本周,1:下周 -1:上周

func IndexOf

func IndexOf(arr []int, tar int) int

func MaxNumber

func MaxNumber(l int) uint64

MaxNumber l位所能表示的最正大数,0<l<=64

func NewCrypto

func NewCrypto(encoding *base64.Encoding) *crypto

func NewRandom

func NewRandom(randomStringSeed string) *random

func ObjectID

func ObjectID(s ...string) (bson.ObjectId, error)

func PKCSSPadding

func PKCSSPadding(data []byte, blockSize int) []byte

PKCSSPadding 填充字节的函数

func PKCSSUnPadding

func PKCSSUnPadding(data []byte) []byte

PKCSSUnPadding 去除填充字节的函数

func Timeout

func Timeout(d time.Duration, fn func() error) error

func Try

func Try(f func(), handler ...func(interface{}))

Types

type ArrayMap

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

func NewArrayMap

func NewArrayMap(cap int32, fixedArray bool) *ArrayMap

func (*ArrayMap) Add

func (r *ArrayMap) Add(value interface{}) int32

func (*ArrayMap) Clone

func (r *ArrayMap) Clone() *ArrayMap

func (*ArrayMap) Del

func (r *ArrayMap) Del(key int32)

func (*ArrayMap) Get

func (r *ArrayMap) Get(key int32) interface{}

func (*ArrayMap) RawGet

func (r *ArrayMap) RawGet(key int32) interface{}

func (*ArrayMap) RawLen

func (r *ArrayMap) RawLen() int32

func (*ArrayMap) Set

func (r *ArrayMap) Set(key int32, value interface{})

type Bitwise

type Bitwise uint

func (*Bitwise) Add

func (m *Bitwise) Add(f int32)

func (*Bitwise) Del

func (m *Bitwise) Del(f int32)

func (*Bitwise) Has

func (m *Bitwise) Has(f int32) bool

位运算

type CryptoType

type CryptoType int
const (
	CryptoTypeDES CryptoType = iota //秘钥长度8字节 也就是64位
	CryptoTypeAES                   //秘钥长度位16 24 32 字节 也就是128 192 256位。
	CryptoType3DES
)

type Job

type Job func(TaskData)

Job callback function

type SCC

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

协程控制器

func NewSCC

func NewSCC(ctx context.Context) *SCC

func (*SCC) CGO

func (s *SCC) CGO(f func(ctx context.Context))

CGO 带有取消通道的协程

func (*SCC) Close

func (s *SCC) Close(cb ...func()) error

Close ,callback:成功调用Close后 cancel之前调用

func (*SCC) Context

func (s *SCC) Context() context.Context

func (*SCC) GO

func (s *SCC) GO(f func())

GO 普通的GO

func (*SCC) Stopped

func (s *SCC) Stopped() bool

判断是否已经关闭

func (*SCC) Wait

func (s *SCC) Wait()

func (*SCC) WaitGroup

func (s *SCC) WaitGroup() *sync.WaitGroup

type TaskData

type TaskData map[interface{}]interface{}

TaskData callback params

type TimeWheel

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

time wheel struct

func New

func New(interval time.Duration, slotNum int) *TimeWheel

New create a empty time wheel

func (*TimeWheel) AddTask

func (tw *TimeWheel) AddTask(interval time.Duration, times int, key interface{}, data TaskData, job Job) error

AddTask add new task to the time wheel

func (*TimeWheel) RemoveTask

func (tw *TimeWheel) RemoveTask(key interface{}) error

RemoveTask remove the task from time wheel

func (*TimeWheel) Start

func (tw *TimeWheel) Start()

Start start the time wheel

func (*TimeWheel) Stop

func (tw *TimeWheel) Stop()

Stop stop the time wheel

func (*TimeWheel) UpdateTask

func (tw *TimeWheel) UpdateTask(key interface{}, interval time.Duration, taskData TaskData) error

UpdateTask update task times and data

type Worker

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

Worker 工作进程管理器,并发安全

func NewWorker

func NewWorker(num int32, handle func(interface{})) *Worker

func (*Worker) Close

func (this *Worker) Close()

关闭Worker

func (*Worker) Emit

func (this *Worker) Emit(msg interface{}) (ret bool)

func (*Worker) Fork

func (this *Worker) Fork()

创建WORKER协程

Jump to

Keyboard shortcuts

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