util

package
Version: v0.0.0-...-cf12e39 Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2018 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CEpoch         = 1474802888000
	CWorkerIdBits  = 10 // Num of WorkerId Bits
	CSenquenceBits = 12 // Num of Sequence Bits

	CWorkerIdShift  = 12
	CTimeStampShift = 22

	CSequenceMask = 0xfff // equal as getSequenceMask()
	CMaxWorker    = 0x3ff // equal as getMaxWorkerId()
)

Variables

This section is empty.

Functions

func GetLongID

func GetLongID() (i int64)

func Lock

func Lock(key string)

func NextID

func NextID() int64

func ParseId

func ParseId(id int64) (t time.Time, ts int64, workerId int64, seq int64)

ParseId Func: reverse uid to timestamp, workid, seq

func QuickSort2

func QuickSort2(arrInter interface{}, compare func(x, y uintptr) bool)

只支持指针数组,通过指针侵入数组,但是对于compare里的uintptr要做转换,如下: str := (*string)(unsafe.Pointer(x))

func RLock

func RLock(key string)

func RUnLock

func RUnLock(key string)

func UnLock

func UnLock(key string)

Types

type IP

type IP struct {
	IP        string `json:"ip"`
	Country   string `json:"country"`
	Area      string `json:"area"`
	Region    string `json:"region"`
	City      string `json:"city"`
	Isp       string `json:"isp"`
	CountryID string `json:"country_id"`
	AreaID    string `json:"area_id"`
	RegionID  string `json:"region_id"`
	CityID    string `json:"city_id"`
	IspID     string `json:"isp_id"`
}

func WatchIP

func WatchIP(addr string) (*IP, error)

type IPInfo

type IPInfo struct {
	Code int `json:"code"`
	Data IP  `json:"data`
}

type IdWorker

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

IdWorker Struct

var IW *IdWorker

func NewIdWorker

func NewIdWorker(workerid int64) (iw *IdWorker, err error)

NewIdWorker Func: Generate NewIdWorker with Given workerid

func (*IdWorker) NextId

func (iw *IdWorker) NextId() (ts int64, err error)

NewId Func: Generate next id

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL