Both game and snake packages had identical PlayerID types and the snake package imported game.GenerateID. Now both use player.ID and player.GenerateID from the shared player package.
19 lines
470 B
Go
19 lines
470 B
Go
// Package player provides shared identity types used across game packages.
|
|
package player
|
|
|
|
import (
|
|
"crypto/rand"
|
|
"encoding/hex"
|
|
)
|
|
|
|
// ID uniquely identifies a player within a session. For authenticated users
|
|
// this is their user UUID; for guests it's a random hex string.
|
|
type ID string
|
|
|
|
// GenerateID returns a random hex string of 2*size characters.
|
|
func GenerateID(size int) string {
|
|
b := make([]byte, size)
|
|
_, _ = rand.Read(b)
|
|
return hex.EncodeToString(b)
|
|
}
|