fusenapi/utils/id_generator/wesocket.go
laodaming 58c0580cad fix
2023-07-27 16:27:42 +08:00

24 lines
361 B
Go

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