@@ -48,7 +48,7 @@ func (s *Socket) fetchInfo() (CGInfo, error) {
48
48
return info , err
49
49
}
50
50
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 ) {
52
52
type request struct {
53
53
Public bool `json:"public"`
54
54
Protected bool `json:"protected"`
@@ -74,15 +74,15 @@ func (s *Socket) createGame(public, protected bool, config any) (gameId string,
74
74
}
75
75
76
76
type response struct {
77
- GameId string `json:"game_id"`
77
+ GameID string `json:"game_id"`
78
78
JoinSecret string `json:"join_secret"`
79
79
}
80
80
var r response
81
81
err = json .NewDecoder (resp .Body ).Decode (& r )
82
- return r .GameId , r .JoinSecret , err
82
+ return r .GameID , r .JoinSecret , err
83
83
}
84
84
85
- func (s * Socket ) createPlayer (gameId , username , joinSecret string ) (string , string , error ) {
85
+ func (s * Socket ) createPlayer (gameID , username , joinSecret string ) (string , string , error ) {
86
86
type request struct {
87
87
Username string `json:"username"`
88
88
JoinSecret string `json:"join_secret,omitempty"`
@@ -96,7 +96,7 @@ func (s *Socket) createPlayer(gameId, username, joinSecret string) (string, stri
96
96
}
97
97
98
98
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 )
100
100
if err != nil {
101
101
return "" , "" , err
102
102
}
@@ -109,42 +109,42 @@ func (s *Socket) createPlayer(gameId, username, joinSecret string) (string, stri
109
109
}
110
110
111
111
type response struct {
112
- PlayerId string `json:"player_id"`
112
+ PlayerID string `json:"player_id"`
113
113
PlayerSecret string `json:"player_secret"`
114
114
}
115
115
var r response
116
116
err = json .NewDecoder (resp .Body ).Decode (& r )
117
- return r .PlayerId , r .PlayerSecret , err
117
+ return r .PlayerID , r .PlayerSecret , err
118
118
}
119
119
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 )
122
122
if err != nil {
123
123
return err
124
124
}
125
125
s .wsConn = wsConn
126
126
return nil
127
127
}
128
128
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 )
131
131
if err != nil {
132
132
return err
133
133
}
134
134
s .wsConn = wsConn
135
135
return nil
136
136
}
137
137
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 ))
140
140
if err != nil {
141
141
return "" , err
142
142
}
143
143
defer resp .Body .Close ()
144
144
if resp .StatusCode != http .StatusOK {
145
145
data , err := io .ReadAll (resp .Body )
146
146
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 ))
148
148
}
149
149
return "" , fmt .Errorf ("invalid response. expected: %d, got: %d" , http .StatusOK , resp .StatusCode )
150
150
}
@@ -157,8 +157,8 @@ func (s *Socket) fetchUsername(gameId, playerId string) (string, error) {
157
157
return r .Username , err
158
158
}
159
159
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 ))
162
162
if err != nil {
163
163
return nil , err
164
164
}
@@ -181,9 +181,9 @@ type configReponse[T any] struct {
181
181
}
182
182
183
183
// 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 ) {
185
185
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 ))
187
187
if err != nil {
188
188
return config , err
189
189
}
0 commit comments