You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
29 lines
454 B
29 lines
454 B
6 years ago
|
/* This module keeps all struct used as singleton */
|
||
|
|
||
|
package utils
|
||
|
|
||
|
import (
|
||
|
"sync"
|
||
|
"sync/atomic"
|
||
|
)
|
||
|
|
||
|
type UniqueValidatorId struct {
|
||
|
uniqueId uint32
|
||
|
}
|
||
|
|
||
|
var instance *UniqueValidatorId
|
||
|
var once sync.Once
|
||
|
|
||
|
func GetUniqueValidatorIdInstance() *UniqueValidatorId {
|
||
|
once.Do(func() {
|
||
|
instance = &UniqueValidatorId{
|
||
|
uniqueId: 0,
|
||
|
}
|
||
|
})
|
||
|
return instance
|
||
|
}
|
||
|
|
||
|
func (s *UniqueValidatorId) GetUniqueId() uint32 {
|
||
|
return atomic.AddUint32(&s.uniqueId, 1)
|
||
|
}
|