feat(qs2) add qs2 framework

This commit is contained in:
hexxa 2020-12-05 10:30:03 +08:00
parent 6ae65fe09b
commit 83100007e3
33 changed files with 2934 additions and 60 deletions

View file

@ -0,0 +1,5 @@
package idgen
type IIDGen interface {
Gen() uint64
}

View file

@ -0,0 +1,27 @@
package simpleidgen
import (
"sync"
"time"
)
var lastID = uint64(0)
var mux = &sync.Mutex{}
type SimpleIDGen struct{}
func New() *SimpleIDGen {
return &SimpleIDGen{}
}
func (id *SimpleIDGen) Gen() uint64 {
mux.Lock()
defer mux.Unlock()
newID := uint64(time.Now().UnixNano())
if newID != lastID {
lastID = newID
return lastID
}
lastID = newID + 1
return lastID
}