mirror of https://github.com/q191201771/naza
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
22 lines
338 B
Go
22 lines
338 B
Go
// package unique 对象唯一ID
|
|
package unique
|
|
|
|
import (
|
|
"fmt"
|
|
"sync/atomic"
|
|
)
|
|
|
|
var global Unique
|
|
|
|
func GenUniqueKey(prefix string) string {
|
|
return global.GenUniqueKey(prefix)
|
|
}
|
|
|
|
type Unique struct {
|
|
id uint64
|
|
}
|
|
|
|
func (u *Unique) GenUniqueKey(prefix string) string {
|
|
return fmt.Sprintf("%s%d", prefix, atomic.AddUint64(&u.id, 1))
|
|
}
|