分支合并
This commit is contained in:
23
utils/id_generator/wesocket.go
Normal file
23
utils/id_generator/wesocket.go
Normal file
@@ -0,0 +1,23 @@
|
||||
package id_generator
|
||||
|
||||
import "sync"
|
||||
|
||||
type WebsocketId struct {
|
||||
nodeId uint64
|
||||
count uint64
|
||||
mu sync.Mutex
|
||||
}
|
||||
|
||||
func (wid *WebsocketId) Get() uint64 {
|
||||
wid.mu.Lock()
|
||||
defer wid.mu.Unlock()
|
||||
wid.count++
|
||||
return (wid.count << 8) | wid.nodeId
|
||||
}
|
||||
|
||||
func NewWebsocketId(NodeId uint8) *WebsocketId {
|
||||
return &WebsocketId{
|
||||
nodeId: uint64(NodeId),
|
||||
count: 0,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user