1
0
mirror of synced 2025-12-15 01:28:09 +08:00
Files
SnowFlake-IdGenerator/Go/source/idgen/YitIdHelper.go

42 lines
777 B
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/*
* 版权属于yitter(yitter@126.com)
* 代码编辑guoyahao
* 代码修订yitter
* 开源地址https://github.com/yitter/idgenerator
*/
package idgen
import (
"sync"
"time"
)
var singletonMutex sync.Mutex
var idGenerator *DefaultIdGenerator
// SetIdGenerator .
func SetIdGenerator(options *IdGeneratorOptions) {
singletonMutex.Lock()
idGenerator = NewDefaultIdGenerator(options)
singletonMutex.Unlock()
}
// NextId .
func NextId() int64 {
//if idGenerator == nil {
// singletonMutex.Lock()
// defer singletonMutex.Unlock()
// if idGenerator == nil {
// options := NewIdGeneratorOptions(1)
// idGenerator = NewDefaultIdGenerator(options)
// }
//}
return idGenerator.NewLong()
}
func ExtractTime(id int64) time.Time {
return idGenerator.ExtractTime(id)
}