-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathplayerid.go
More file actions
46 lines (37 loc) · 1.13 KB
/
playerid.go
File metadata and controls
46 lines (37 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package rlapi
import (
"fmt"
"strings"
)
// PlayerID represents a unique player identifier in the format "Platform|ID|0"
type PlayerID string
// Platform represents a gaming platform
type Platform string
// Platform constants
const (
PlatformEpic Platform = "Epic"
PlatformSteam Platform = "Steam"
PlatformPS4 Platform = "PS4"
PlatformXbox Platform = "XboxOne"
PlatformSwitch Platform = "Switch"
)
// String returns the string representation of Platform
func (p Platform) String() string {
return string(p)
}
// NewPlayerID creates a PlayerID for the specified platform and ID
func NewPlayerID(platform Platform, id string) PlayerID {
return PlayerID(fmt.Sprintf("%s|%s|0", platform, id))
}
// ParsePlayerID parses a PlayerID string and returns its components
func ParsePlayerID(playerID string) (platform Platform, id string, err error) {
parts := strings.Split(playerID, "|")
if len(parts) != 3 {
return "", "", fmt.Errorf("invalid PlayerID format: %s", playerID)
}
return Platform(parts[0]), parts[1], nil
}
// String returns the string representation of PlayerID
func (p PlayerID) String() string {
return string(p)
}