@@ -59,7 +59,7 @@ func GameRegister() {
59
59
Description: Displays a list of all games in the database.
60
60
*/
61
61
func list_games (ctx * iris.Context ) {
62
- var games []objects.Game
62
+ games := []objects.Game {}
63
63
includeInactive := ctx .URLParam ("includeInactive" )
64
64
val , err := strconv .ParseBool (includeInactive )
65
65
if (err != nil ) && val {
@@ -81,8 +81,8 @@ func list_games(ctx *iris.Context) {
81
81
*/
82
82
func show_game (ctx * iris.Context ) {
83
83
gameshort := ctx .GetString ("gameshort" )
84
- var game objects.Game
85
- SpaceDock .Database .Where ("short = ?" , gameshort ).First (& game )
84
+ game := & objects.Game {}
85
+ SpaceDock .Database .Where ("short = ?" , gameshort ).First (game )
86
86
if game .Short != gameshort {
87
87
utils .WriteJSON (ctx , iris .StatusNotFound , utils .Error ("The game does not exist." ).Code (2125 ))
88
88
return
@@ -98,15 +98,15 @@ func show_game(ctx *iris.Context) {
98
98
*/
99
99
func edit_game (ctx * iris.Context ) {
100
100
gameshort := ctx .GetString ("gameshort" )
101
- var game objects.Game
102
- SpaceDock .Database .Where ("short = ?" , gameshort ).First (& game )
101
+ game := & objects.Game {}
102
+ SpaceDock .Database .Where ("short = ?" , gameshort ).First (game )
103
103
if game .Short != gameshort {
104
104
utils .WriteJSON (ctx , iris .StatusNotFound , utils .Error ("The game does not exist." ).Code (2125 ))
105
105
return
106
106
}
107
107
108
108
// Edit the game
109
- code := utils .EditObject (& game , utils .GetFullJSON (ctx ))
109
+ code := utils .EditObject (game , utils .GetFullJSON (ctx ))
110
110
if code == 3 {
111
111
utils .WriteJSON (ctx , iris .StatusBadRequest , utils .Error ("The value you submitted is invalid" ).Code (2180 ))
112
112
return
@@ -117,7 +117,7 @@ func edit_game(ctx *iris.Context) {
117
117
utils .WriteJSON (ctx , iris .StatusBadRequest , utils .Error ("You tried to edit a value that is marked as read-only." ).Code (3095 ))
118
118
return
119
119
}
120
- SpaceDock .Database .Save (& game )
120
+ SpaceDock .Database .Save (game )
121
121
utils .WriteJSON (ctx , iris .StatusOK , iris.Map {"error" : false , "count" : 1 , "data" : utils .ToMap (game )})
122
122
}
123
123
@@ -136,8 +136,8 @@ func add_game(ctx *iris.Context) {
136
136
codes := []int {}
137
137
138
138
// Check if the publisher ID is valid
139
- var publisher objects.Publisher
140
- SpaceDock .Database .Where ("id = ?" , pubid ).First (& publisher )
139
+ publisher := objects.Publisher {}
140
+ SpaceDock .Database .Where ("id = ?" , pubid ).First (publisher )
141
141
if publisher .ID != pubid {
142
142
errors = append (errors , "The pubid is invalid." )
143
143
codes = append (codes , 2110 )
@@ -152,13 +152,13 @@ func add_game(ctx *iris.Context) {
152
152
}
153
153
154
154
// Check if the game already exists
155
- var game * objects.Game
155
+ game := & objects.Game {}
156
156
SpaceDock .Database .Where ("short = ?" , short ).First (game )
157
157
if game .Short == short {
158
158
errors = append (errors , "The gameshort already exists." )
159
159
codes = append (codes , 2015 )
160
160
}
161
- SpaceDock .Database .Where ("name = ?" , name ).First (& game )
161
+ SpaceDock .Database .Where ("name = ?" , name ).First (game )
162
162
if game .Name == name {
163
163
errors = append (errors , "The game name already exists." )
164
164
codes = append (codes , 2020 )
@@ -173,7 +173,7 @@ func add_game(ctx *iris.Context) {
173
173
// Make a new game
174
174
game = objects .NewGame (name , publisher , short )
175
175
SpaceDock .Database .Save (game )
176
- utils .WriteJSON (ctx , iris .StatusOK , iris.Map {"error" : false , "count" : 1 , "data" : utils .ToMap (* game )})
176
+ utils .WriteJSON (ctx , iris .StatusOK , iris.Map {"error" : false , "count" : 1 , "data" : utils .ToMap (game )})
177
177
}
178
178
179
179
/*
@@ -186,7 +186,7 @@ func remove_game(ctx *iris.Context) {
186
186
short := cast .ToString (utils .GetJSON (ctx , "short" ))
187
187
188
188
// Check if the game exists
189
- var game * objects.Game
189
+ game := & objects.Game {}
190
190
SpaceDock .Database .Where ("short = ?" , short ).First (game )
191
191
if game .Short != short {
192
192
utils .WriteJSON (ctx , iris .StatusNotFound , utils .Error ("The game does not exist." ).Code (2125 ))
@@ -205,8 +205,8 @@ func remove_game(ctx *iris.Context) {
205
205
*/
206
206
func game_versions (ctx * iris.Context ) {
207
207
gameshort := ctx .GetString ("gameshort" )
208
- var game objects.Game
209
- SpaceDock .Database .Where ("short = ?" , gameshort ).First (& game )
208
+ game := & objects.Game {}
209
+ SpaceDock .Database .Where ("short = ?" , gameshort ).First (game )
210
210
if game .Short != gameshort {
211
211
utils .WriteJSON (ctx , iris .StatusNotFound , utils .Error ("The game does not exist." ).Code (2125 ))
212
212
return
@@ -228,8 +228,8 @@ func game_versions(ctx *iris.Context) {
228
228
*/
229
229
func game_version_add (ctx * iris.Context ) {
230
230
gameshort := ctx .GetString ("gameshort" )
231
- var game objects.Game
232
- SpaceDock .Database .Where ("short = ?" , gameshort ).First (& game )
231
+ game := & objects.Game {}
232
+ SpaceDock .Database .Where ("short = ?" , gameshort ).First (game )
233
233
if game .Short != gameshort {
234
234
utils .WriteJSON (ctx , iris .StatusNotFound , utils .Error ("The game does not exist." ).Code (2125 ))
235
235
return
@@ -240,7 +240,7 @@ func game_version_add(ctx *iris.Context) {
240
240
is_beta := cast .ToBool (utils .GetJSON (ctx , "is_beta" ))
241
241
242
242
// Create a new version
243
- version := objects .NewGameVersion (friendly_version , game , is_beta )
243
+ version := objects .NewGameVersion (friendly_version , * game , is_beta )
244
244
SpaceDock .Database .Save (version )
245
245
246
246
// Format the output
@@ -255,16 +255,16 @@ func game_version_add(ctx *iris.Context) {
255
255
*/
256
256
func game_version_remove (ctx * iris.Context ) {
257
257
gameshort := ctx .GetString ("gameshort" )
258
- var game objects.Game
259
- SpaceDock .Database .Where ("short = ?" , gameshort ).First (& game )
258
+ game := & objects.Game {}
259
+ SpaceDock .Database .Where ("short = ?" , gameshort ).First (game )
260
260
if game .Short != gameshort {
261
261
utils .WriteJSON (ctx , iris .StatusNotFound , utils .Error ("The game does not exist." ).Code (2125 ))
262
262
return
263
263
}
264
264
265
265
// Get game version
266
266
friendly_version := cast .ToString (utils .GetJSON (ctx , "friendly_version" ))
267
- var version * objects.GameVersion
267
+ version := & objects.GameVersion {}
268
268
SpaceDock .Database .Where ("friendly_version = ?" , friendly_version ).Where ("game_id = ?" , game .ID ).First (version )
269
269
if version .FriendlyVersion != friendly_version {
270
270
utils .WriteJSON (ctx , iris .StatusNotFound , utils .Error ("This version name does not exist." ).Code (2185 ))
@@ -285,17 +285,17 @@ func game_version_remove(ctx *iris.Context) {
285
285
*/
286
286
func game_version_show (ctx * iris.Context ) {
287
287
gameshort := ctx .GetString ("gameshort" )
288
- var game objects.Game
289
- SpaceDock .Database .Where ("short = ?" , gameshort ).First (& game )
288
+ game := & objects.Game {}
289
+ SpaceDock .Database .Where ("short = ?" , gameshort ).First (game )
290
290
if game .Short != gameshort {
291
291
utils .WriteJSON (ctx , iris .StatusNotFound , utils .Error ("The game does not exist." ).Code (2125 ))
292
292
return
293
293
}
294
294
295
295
// Get game version
296
296
friendly_version := ctx .GetString ("friendly_version" )
297
- var version objects.GameVersion
298
- SpaceDock .Database .Where ("friendly_version = ?" , friendly_version ).Where ("game_id = ?" , game .ID ).First (& version )
297
+ version := & objects.GameVersion {}
298
+ SpaceDock .Database .Where ("friendly_version = ?" , friendly_version ).Where ("game_id = ?" , game .ID ).First (version )
299
299
if version .FriendlyVersion != friendly_version {
300
300
utils .WriteJSON (ctx , iris .StatusNotFound , utils .Error ("This version name does not exist." ).Code (2185 ))
301
301
return
@@ -313,24 +313,24 @@ func game_version_show(ctx *iris.Context) {
313
313
*/
314
314
func game_version_edit (ctx * iris.Context ) {
315
315
gameshort := ctx .GetString ("gameshort" )
316
- var game objects.Game
317
- SpaceDock .Database .Where ("short = ?" , gameshort ).First (& game )
316
+ game := & objects.Game {}
317
+ SpaceDock .Database .Where ("short = ?" , gameshort ).First (game )
318
318
if game .Short != gameshort {
319
319
utils .WriteJSON (ctx , iris .StatusNotFound , utils .Error ("The game does not exist." ).Code (2125 ))
320
320
return
321
321
}
322
322
323
323
// Get game version
324
324
friendly_version := ctx .GetString ("friendly_version" )
325
- var version objects.GameVersion
326
- SpaceDock .Database .Where ("friendly_version = ?" , friendly_version ).Where ("game_id = ?" , game .ID ).First (& version )
325
+ version := & objects.GameVersion {}
326
+ SpaceDock .Database .Where ("friendly_version = ?" , friendly_version ).Where ("game_id = ?" , game .ID ).First (version )
327
327
if version .FriendlyVersion != friendly_version {
328
328
utils .WriteJSON (ctx , iris .StatusNotFound , utils .Error ("This version name does not exist." ).Code (2185 ))
329
329
return
330
330
}
331
331
332
332
// Edit the game version
333
- code := utils .EditObject (& version , utils .GetFullJSON (ctx ))
333
+ code := utils .EditObject (version , utils .GetFullJSON (ctx ))
334
334
if code == 3 {
335
335
utils .WriteJSON (ctx , iris .StatusBadRequest , utils .Error ("The value you submitted is invalid" ).Code (2180 ))
336
336
return
@@ -341,6 +341,6 @@ func game_version_edit(ctx *iris.Context) {
341
341
utils .WriteJSON (ctx , iris .StatusBadRequest , utils .Error ("You tried to edit a value that is marked as read-only." ).Code (3095 ))
342
342
return
343
343
}
344
- SpaceDock .Database .Save (& version )
344
+ SpaceDock .Database .Save (version )
345
345
utils .WriteJSON (ctx , iris .StatusOK , iris.Map {"error" : false , "count" : 1 , "data" : utils .ToMap (version )})
346
346
}
0 commit comments