1
0
mirror of synced 2026-04-12 11:28:39 +08:00

auto commit

This commit is contained in:
yitter
2021-04-05 15:01:33 +08:00
parent e9c6ad0294
commit acaefa52f5

View File

@@ -1,68 +1,28 @@
/*
* 版权属于yitter(yitter@126.com)
* 代码编辑guoyahao
* 代码修订yitter
* 开源地址https://gitee.com/yitter/idgenerator
*/
package idgen
import (
"sync"
)
//var yitIdHelper *YitIdHelper
//var once sync.Once
var idGenerator *DefaultIdGenerator
var singletonMutex sync.Mutex
var idGenerator *DefaultIdGenerator
type YitIdHelper struct {
idGenInstance interface {
NewLong() uint64
}
}
//
//func GetIns() *YitIdHelper {
// once.Do(func() {
// yitIdHelper = &YitIdHelper{}
// })
// return yitIdHelper
//}
//
//func (yih *YitIdHelper) GetIdGenInstance() interface{} {
// return yih.idGenInstance
//}
//
//func (yih *YitIdHelper) SetIdGenerator(options *contract.IdGeneratorOptions) {
// yih.idGenInstance = NewDefaultIdGenerator(options)
//}
//
//func (yih *YitIdHelper) NextId() uint64 {
// once.Do(func() {
// if yih.idGenInstance == nil {
// options := contract.NewIdGeneratorOptions(1)
// yih.idGenInstance = NewDefaultIdGenerator(options)
// }
// })
//
// return yih.idGenInstance.NewLong()
//}
// SetIdGenerator .
func SetIdGenerator(options *IdGeneratorOptions) {
singletonMutex.Lock()
idGenerator = NewDefaultIdGenerator(options)
singletonMutex.Unlock()
}
// NextId .
func NextId() uint64 {
if idGenerator == nil {
singletonMutex.Lock()
defer singletonMutex.Unlock()
if idGenerator == nil {
options := NewIdGeneratorOptions(1)
idGenerator = NewDefaultIdGenerator(options)
}
singletonMutex.Unlock()
}
return idGenerator.NewLong()