Skip to content

Commit 1dbed27

Browse files
committed
Id -> ID
1 parent ed49c0a commit 1dbed27

File tree

9 files changed

+80
-79
lines changed

9 files changed

+80
-79
lines changed

LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2022 Julian Hofmann
3+
Copyright (c) 2022-2023 Julian Hofmann
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ for {
7171

7272
MIT License
7373

74-
Copyright (c) 2022 Julian Hofmann
74+
Copyright (c) 2022-2023 Julian Hofmann
7575

7676
Permission is hereby granted, free of charge, to any person obtaining a copy
7777
of this software and associated documentation files (the "Software"), to deal

cg/api.go

+18-18
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func (s *Socket) fetchInfo() (CGInfo, error) {
4848
return info, err
4949
}
5050

51-
func (s *Socket) createGame(public, protected bool, config any) (gameId string, joinSecret string, err error) {
51+
func (s *Socket) createGame(public, protected bool, config any) (gameID string, joinSecret string, err error) {
5252
type request struct {
5353
Public bool `json:"public"`
5454
Protected bool `json:"protected"`
@@ -74,15 +74,15 @@ func (s *Socket) createGame(public, protected bool, config any) (gameId string,
7474
}
7575

7676
type response struct {
77-
GameId string `json:"game_id"`
77+
GameID string `json:"game_id"`
7878
JoinSecret string `json:"join_secret"`
7979
}
8080
var r response
8181
err = json.NewDecoder(resp.Body).Decode(&r)
82-
return r.GameId, r.JoinSecret, err
82+
return r.GameID, r.JoinSecret, err
8383
}
8484

85-
func (s *Socket) createPlayer(gameId, username, joinSecret string) (string, string, error) {
85+
func (s *Socket) createPlayer(gameID, username, joinSecret string) (string, string, error) {
8686
type request struct {
8787
Username string `json:"username"`
8888
JoinSecret string `json:"join_secret,omitempty"`
@@ -96,7 +96,7 @@ func (s *Socket) createPlayer(gameId, username, joinSecret string) (string, stri
9696
}
9797

9898
body := bytes.NewBuffer(data)
99-
resp, err := http.Post(baseURL("http", s.tls, "%s/api/games/%s/players", s.url, gameId), "application/json", body)
99+
resp, err := http.Post(baseURL("http", s.tls, "%s/api/games/%s/players", s.url, gameID), "application/json", body)
100100
if err != nil {
101101
return "", "", err
102102
}
@@ -109,42 +109,42 @@ func (s *Socket) createPlayer(gameId, username, joinSecret string) (string, stri
109109
}
110110

111111
type response struct {
112-
PlayerId string `json:"player_id"`
112+
PlayerID string `json:"player_id"`
113113
PlayerSecret string `json:"player_secret"`
114114
}
115115
var r response
116116
err = json.NewDecoder(resp.Body).Decode(&r)
117-
return r.PlayerId, r.PlayerSecret, err
117+
return r.PlayerID, r.PlayerSecret, err
118118
}
119119

120-
func (s *Socket) connect(gameId, playerId, playerSecret string) error {
121-
wsConn, _, err := websocket.DefaultDialer.Dial(baseURL("ws", s.tls, "%s/api/games/%s/players/%s/connect?player_secret=%s", s.url, gameId, playerId, playerSecret), nil)
120+
func (s *Socket) connect(gameID, playerID, playerSecret string) error {
121+
wsConn, _, err := websocket.DefaultDialer.Dial(baseURL("ws", s.tls, "%s/api/games/%s/players/%s/connect?player_secret=%s", s.url, gameID, playerID, playerSecret), nil)
122122
if err != nil {
123123
return err
124124
}
125125
s.wsConn = wsConn
126126
return nil
127127
}
128128

129-
func (s *Socket) spectate(gameId string) error {
130-
wsConn, _, err := websocket.DefaultDialer.Dial(baseURL("ws", s.tls, "%s/api/games/%s/spectate", s.url, gameId), nil)
129+
func (s *Socket) spectate(gameID string) error {
130+
wsConn, _, err := websocket.DefaultDialer.Dial(baseURL("ws", s.tls, "%s/api/games/%s/spectate", s.url, gameID), nil)
131131
if err != nil {
132132
return err
133133
}
134134
s.wsConn = wsConn
135135
return nil
136136
}
137137

138-
func (s *Socket) fetchUsername(gameId, playerId string) (string, error) {
139-
resp, err := http.Get(baseURL("http", s.tls, "%s/api/games/%s/players/%s", s.url, gameId, playerId))
138+
func (s *Socket) fetchUsername(gameID, playerID string) (string, error) {
139+
resp, err := http.Get(baseURL("http", s.tls, "%s/api/games/%s/players/%s", s.url, gameID, playerID))
140140
if err != nil {
141141
return "", err
142142
}
143143
defer resp.Body.Close()
144144
if resp.StatusCode != http.StatusOK {
145145
data, err := io.ReadAll(resp.Body)
146146
if err == nil && len(data) > 0 {
147-
return "", fmt.Errorf("Failed to fetch username of %s: %s", playerId, string(data))
147+
return "", fmt.Errorf("Failed to fetch username of %s: %s", playerID, string(data))
148148
}
149149
return "", fmt.Errorf("invalid response. expected: %d, got: %d", http.StatusOK, resp.StatusCode)
150150
}
@@ -157,8 +157,8 @@ func (s *Socket) fetchUsername(gameId, playerId string) (string, error) {
157157
return r.Username, err
158158
}
159159

160-
func (s *Socket) fetchPlayers(gameId string) (map[string]string, error) {
161-
resp, err := http.Get(baseURL("http", s.tls, "%s/api/games/%s/players", s.url, gameId))
160+
func (s *Socket) fetchPlayers(gameID string) (map[string]string, error) {
161+
resp, err := http.Get(baseURL("http", s.tls, "%s/api/games/%s/players", s.url, gameID))
162162
if err != nil {
163163
return nil, err
164164
}
@@ -181,9 +181,9 @@ type configReponse[T any] struct {
181181
}
182182

183183
// FetchGameConfig fetches the game config from the server.
184-
func FetchGameConfig[T any](socket *Socket, gameId string) (T, error) {
184+
func FetchGameConfig[T any](socket *Socket, gameID string) (T, error) {
185185
var config T
186-
resp, err := http.Get(baseURL("http", socket.tls, "%s/api/games/%s", socket.url, gameId))
186+
resp, err := http.Get(baseURL("http", socket.tls, "%s/api/games/%s", socket.url, gameID))
187187
if err != nil {
188188
return config, err
189189
}

cg/debug_socket.go

+9-9
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ type DebugMessageCallback func(severity DebugSeverity, message string, data stri
2828

2929
type DebugSocket struct {
3030
wsConn *websocket.Conn
31-
callbacks map[CallbackId]DebugMessageCallback
31+
callbacks map[CallbackID]DebugMessageCallback
3232
url string
3333
tls bool
3434

@@ -41,7 +41,7 @@ type DebugSocket struct {
4141
func NewDebugSocket(url string) *DebugSocket {
4242
url = trimURL(url)
4343
return &DebugSocket{
44-
callbacks: make(map[CallbackId]DebugMessageCallback),
44+
callbacks: make(map[CallbackID]DebugMessageCallback),
4545
url: url,
4646
tls: isTLS(url),
4747
enableTrace: false,
@@ -68,13 +68,13 @@ func (s *DebugSocket) SetSeverities(enableTrace, enableInfo, enableWarning, enab
6868
s.enableError = enableError
6969
}
7070

71-
func (s *DebugSocket) OnMessage(callback DebugMessageCallback) CallbackId {
72-
id := CallbackId(uuid.New())
71+
func (s *DebugSocket) OnMessage(callback DebugMessageCallback) CallbackID {
72+
id := CallbackID(uuid.New())
7373
s.callbacks[id] = callback
7474
return id
7575
}
7676

77-
func (s *DebugSocket) RemoveCallback(id CallbackId) {
77+
func (s *DebugSocket) RemoveCallback(id CallbackID) {
7878
delete(s.callbacks, id)
7979
}
8080

@@ -91,8 +91,8 @@ func (s *DebugSocket) DebugServer() error {
9191
}
9292

9393
// DebugGame connects to the /api/games/{gameId}/debug endpoint on the server and listens for debug messages.
94-
func (s *DebugSocket) DebugGame(gameId string) error {
95-
wsConn, _, err := websocket.DefaultDialer.Dial(baseURL("ws", s.tls, "%s/api/games/%s/debug?trace=%t&info=%t&warning=%t&error=%t", s.url, gameId, s.enableTrace, s.enableInfo, s.enableWarning, s.enableError), nil)
94+
func (s *DebugSocket) DebugGame(gameID string) error {
95+
wsConn, _, err := websocket.DefaultDialer.Dial(baseURL("ws", s.tls, "%s/api/games/%s/debug?trace=%t&info=%t&warning=%t&error=%t", s.url, gameID, s.enableTrace, s.enableInfo, s.enableWarning, s.enableError), nil)
9696
if err != nil {
9797
return err
9898
}
@@ -103,8 +103,8 @@ func (s *DebugSocket) DebugGame(gameId string) error {
103103
}
104104

105105
// DebugPlayer connects to the /api/games/{gameId}/players/{playerId}/debug endpoint on the server and listens for debug messages.
106-
func (s *DebugSocket) DebugPlayer(gameId, playerId, playerSecret string) error {
107-
wsConn, _, err := websocket.DefaultDialer.Dial(baseURL("ws", s.tls, "%s/api/games/%s/players/%s/debug?player_secret=%s&trace=%t&info=%t&warning=%t&error=%t", s.url, gameId, playerId, playerSecret, s.enableTrace, s.enableInfo, s.enableWarning, s.enableError), nil)
106+
func (s *DebugSocket) DebugPlayer(gameID, playerID, playerSecret string) error {
107+
wsConn, _, err := websocket.DefaultDialer.Dial(baseURL("ws", s.tls, "%s/api/games/%s/players/%s/debug?player_secret=%s&trace=%t&info=%t&warning=%t&error=%t", s.url, gameID, playerID, playerSecret, s.enableTrace, s.enableInfo, s.enableWarning, s.enableError), nil)
108108
if err != nil {
109109
return err
110110
}

cg/event.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@ import (
66
"github.com/google/uuid"
77
)
88

9-
type CallbackId uuid.UUID
10-
type EventCallback func(event Event)
9+
type (
10+
CallbackID uuid.UUID
11+
EventCallback func(event Event)
12+
)
1113

1214
type EventName string
1315

cg/session.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,19 @@ import (
1313
type Session struct {
1414
GameURL string `json:"-"`
1515
Username string `json:"-"`
16-
GameId string `json:"game_id"`
17-
PlayerId string `json:"player_id"`
16+
GameID string `json:"game_id"`
17+
PlayerID string `json:"player_id"`
1818
PlayerSecret string `json:"player_secret"`
1919
}
2020

2121
var gamesPath = filepath.Join(xdg.DataHome, "codegame", "games")
2222

23-
func newSession(gameURL, username, gameId, playerId, playerSecret string) Session {
23+
func newSession(gameURL, username, gameID, playerID, playerSecret string) Session {
2424
return Session{
2525
GameURL: gameURL,
2626
Username: username,
27-
GameId: gameId,
28-
PlayerId: playerId,
27+
GameID: gameID,
28+
PlayerID: playerID,
2929
PlayerSecret: playerSecret,
3030
}
3131
}

0 commit comments

Comments
 (0)