This commit is contained in:
laodaming
2023-07-27 16:27:42 +08:00
parent 4eb37c3820
commit 58c0580cad
3 changed files with 36 additions and 10 deletions

View 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,
}
}