feat(qs2) add qs2 framework
This commit is contained in:
parent
6ae65fe09b
commit
83100007e3
33 changed files with 2934 additions and 60 deletions
5
src/idgen/idgen_interface.go
Normal file
5
src/idgen/idgen_interface.go
Normal file
|
@ -0,0 +1,5 @@
|
|||
package idgen
|
||||
|
||||
type IIDGen interface {
|
||||
Gen() uint64
|
||||
}
|
27
src/idgen/simpleidgen/simple_id_gen.go
Normal file
27
src/idgen/simpleidgen/simple_id_gen.go
Normal 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
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue