Skip to content

Commit cb81b59

Browse files
Luckiboppreh
authored andcommitted
statisfy golint
1 parent 0cab526 commit cb81b59

File tree

6 files changed

+119
-119
lines changed

6 files changed

+119
-119
lines changed

backup.go

+11-11
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414

1515
// BackupGame if a game has a custom image, backs it up by appending "(original)" to the
1616
// file name.
17-
func BackupGame(gridDir string, game *Game, artStyleExtensions []string) error {
17+
func backupGame(gridDir string, game *Game, artStyleExtensions []string) error {
1818
if game.CleanImageBytes != nil {
1919
return ioutil.WriteFile(getBackupPath(gridDir, game, artStyleExtensions), game.CleanImageBytes, 0666)
2020
}
@@ -25,17 +25,17 @@ func getBackupPath(gridDir string, game *Game, artStyleExtensions []string) stri
2525
hash := sha256.Sum256(game.OverlayImageBytes)
2626
// [:] is required to convert a fixed length byte array to a byte slice.
2727
hexHash := hex.EncodeToString(hash[:])
28-
return filepath.Join(gridDir, "originals", game.ID + artStyleExtensions[0] + " " + hexHash+game.ImageExt)
28+
return filepath.Join(gridDir, "originals", game.ID+artStyleExtensions[0]+" "+hexHash+game.ImageExt)
2929
}
3030

31-
func RemoveExisting(gridDir string, gameId string, artStyleExtensions []string) error {
32-
images, err := filepath.Glob(filepath.Join(gridDir, gameId + artStyleExtensions[0] + ".*"))
31+
func removeExisting(gridDir string, gameID string, artStyleExtensions []string) error {
32+
images, err := filepath.Glob(filepath.Join(gridDir, gameID+artStyleExtensions[0]+".*"))
3333
if err != nil {
3434
return err
3535
}
3636
images = filterForImages(images)
3737

38-
backups, err := filepath.Glob(filepath.Join(gridDir, "originals", gameId + artStyleExtensions[0] + " *.*"))
38+
backups, err := filepath.Glob(filepath.Join(gridDir, "originals", gameID+artStyleExtensions[0]+" *.*"))
3939
if err != nil {
4040
return err
4141
}
@@ -63,7 +63,7 @@ func loadImage(game *Game, sourceName string, imagePath string) error {
6363
}
6464

6565
// https://wenzr.wordpress.com/2018/04/09/go-glob-case-insensitive/
66-
func InsensitiveFilepath(path string) string {
66+
func insensitiveFilepath(path string) string {
6767
if runtime.GOOS == "windows" {
6868
return path
6969
}
@@ -95,8 +95,8 @@ func filterForImages(paths []string) []string {
9595
return matchedPaths
9696
}
9797

98-
func LoadExisting(overridePath string, gridDir string, game *Game, artStyleExtensions []string) {
99-
overridenIDs, _ := filepath.Glob(filepath.Join(overridePath, game.ID + artStyleExtensions[0] + ".*"))
98+
func loadExisting(overridePath string, gridDir string, game *Game, artStyleExtensions []string) {
99+
overridenIDs, _ := filepath.Glob(filepath.Join(overridePath, game.ID+artStyleExtensions[0]+".*"))
100100
if overridenIDs != nil && len(overridenIDs) > 0 {
101101
loadImage(game, "local file in directory 'games'", overridenIDs[0])
102102
return
@@ -106,15 +106,15 @@ func LoadExisting(overridePath string, gridDir string, game *Game, artStyleExten
106106
if game.Name != "" {
107107
re := regexp.MustCompile(`\W+`)
108108
globName := re.ReplaceAllString(game.Name, "*")
109-
overridenNames, _ := filepath.Glob(filepath.Join(overridePath, InsensitiveFilepath(globName) + artStyleExtensions[1] + ".*"))
109+
overridenNames, _ := filepath.Glob(filepath.Join(overridePath, insensitiveFilepath(globName)+artStyleExtensions[1]+".*"))
110110
if overridenNames != nil && len(overridenNames) > 0 {
111111
loadImage(game, "local file in directory games/", overridenNames[0])
112112
return
113113
}
114114
}
115115

116116
// If there are any old-style backups (without hash), load them over the existing (with overlay) images.
117-
oldBackups, err := filepath.Glob(filepath.Join(gridDir, game.ID + artStyleExtensions[0] + " (original)*"))
117+
oldBackups, err := filepath.Glob(filepath.Join(gridDir, game.ID+artStyleExtensions[0]+" (original)*"))
118118
if err == nil && len(oldBackups) > 0 {
119119
err = loadImage(game, "legacy backup (now converted)", oldBackups[0])
120120
if err == nil {
@@ -123,7 +123,7 @@ func LoadExisting(overridePath string, gridDir string, game *Game, artStyleExten
123123
}
124124
}
125125

126-
files, err := filepath.Glob(filepath.Join(gridDir, game.ID + artStyleExtensions[0] + ".*"))
126+
files, err := filepath.Glob(filepath.Join(gridDir, game.ID+artStyleExtensions[0]+".*"))
127127
files = filterForImages(files)
128128
if err == nil && len(files) > 0 {
129129
err = loadImage(game, "manual customization", files[0])

download.go

+64-65
Original file line numberDiff line numberDiff line change
@@ -66,43 +66,43 @@ func getGoogleImage(gameName string, artStyleExtensions []string) (string, error
6666
}
6767

6868
// https://www.steamgriddb.com/api/v2
69-
type SteamGridDBResponse struct {
69+
type steamGridDBResponse struct {
7070
Success bool
71-
Data []struct {
72-
Id int
73-
Score int
74-
Style string
75-
Url string
76-
Thumb string
77-
Tags []string
71+
Data []struct {
72+
ID int
73+
Score int
74+
Style string
75+
URL string
76+
Thumb string
77+
Tags []string
7878
Author struct {
79-
Name string
79+
Name string
8080
Steam64 string
81-
Avatar string
81+
Avatar string
8282
}
8383
}
8484
}
8585

86-
type SteamGridDBSearchResponse struct {
86+
type steamGridDBSearchResponse struct {
8787
Success bool
88-
Data []struct {
89-
Id int
90-
Name string
91-
Types []string
88+
Data []struct {
89+
ID int
90+
Name string
91+
Types []string
9292
Verified bool
9393
}
9494
}
9595

9696
// Search SteamGridDB for cover image
97-
const SteamGridDBBaseURL = "https://www.steamgriddb.com/api/v2"
97+
const steamGridDBBaseURL = "https://www.steamgriddb.com/api/v2"
9898

99-
func SteamGridDBGetRequest(url string, steamGridDBApiKey string) ([]byte, error) {
99+
func steamGridDBGetRequest(url string, steamGridDBApiKey string) ([]byte, error) {
100100
client := &http.Client{}
101101
req, err := http.NewRequest("GET", url, nil)
102102
if err != nil {
103103
return nil, err
104104
}
105-
req.Header.Add("Authorization", "Bearer " + steamGridDBApiKey)
105+
req.Header.Add("Authorization", "Bearer "+steamGridDBApiKey)
106106

107107
response, err := client.Do(req)
108108
if err != nil {
@@ -130,67 +130,66 @@ func getSteamGridDBImage(game *Game, artStyleExtensions []string, steamGridDBApi
130130
// Try for HQ, then for LQ
131131
// It's possible to request both dimensions in one go but that'll give us scrambled results with no indicator which result has which size.
132132
for i := 0; i < 3; i += 2 {
133-
filter := steamGridFilter + "&dimensions=" + artStyleExtensions[3 + i] + "x" + artStyleExtensions[4 + i]
133+
filter := steamGridFilter + "&dimensions=" + artStyleExtensions[3+i] + "x" + artStyleExtensions[4+i]
134134

135135
// Try with game.ID which is probably steams appID
136-
var baseUrl string
136+
var baseURL string
137137
switch artStyleExtensions[1] {
138138
case ".banner":
139-
baseUrl = SteamGridDBBaseURL + "/grids"
139+
baseURL = steamGridDBBaseURL + "/grids"
140140
case ".cover":
141-
baseUrl = SteamGridDBBaseURL + "/grids"
141+
baseURL = steamGridDBBaseURL + "/grids"
142142
case ".hero":
143-
baseUrl = SteamGridDBBaseURL + "/heroes"
143+
baseURL = steamGridDBBaseURL + "/heroes"
144144
case ".logo":
145-
baseUrl = SteamGridDBBaseURL + "/logos"
145+
baseURL = steamGridDBBaseURL + "/logos"
146146
}
147-
url := baseUrl + "/steam/" + game.ID + filter
147+
url := baseURL + "/steam/" + game.ID + filter
148148

149-
var jsonResponse SteamGridDBResponse
149+
var jsonResponse steamGridDBResponse
150150
var responseBytes []byte
151151
var err error
152152

153153
// Skip requests with appID for custom games
154154
if !game.Custom {
155-
responseBytes, err = SteamGridDBGetRequest(url, steamGridDBApiKey)
155+
responseBytes, err = steamGridDBGetRequest(url, steamGridDBApiKey)
156156
} else {
157157
err = errors.New("404")
158158
}
159159

160160
// Authorization token is missing or invalid
161-
if err != nil && err.Error() == "401" {
161+
if err != nil && err.Error() == "401" {
162162
return "", errors.New("SteamGridDB authorization token is missing or invalid")
163-
// Could not find game with that id
163+
// Could not find game with that id
164164
} else if err != nil && err.Error() == "404" {
165165
// Try searching for the name…
166-
url = SteamGridDBBaseURL + "/search/autocomplete/" + game.Name + filter
167-
responseBytes, err = SteamGridDBGetRequest(url, steamGridDBApiKey)
166+
url = steamGridDBBaseURL + "/search/autocomplete/" + game.Name + filter
167+
responseBytes, err = steamGridDBGetRequest(url, steamGridDBApiKey)
168168
if err != nil && err.Error() == "401" {
169169
return "", errors.New("SteamGridDB authorization token is missing or invalid")
170170
} else if err != nil {
171171
return "", err
172172
}
173173

174-
var jsonSearchResponse SteamGridDBSearchResponse
174+
var jsonSearchResponse steamGridDBSearchResponse
175175
err = json.Unmarshal(responseBytes, &jsonSearchResponse)
176176
if err != nil {
177177
return "", errors.New("Best search match doesn't has a requested type or style")
178178
}
179179

180-
SteamGridDBGameId := -1
180+
SteamGridDBGameID := -1
181181
if jsonSearchResponse.Success && len(jsonSearchResponse.Data) >= 1 {
182182
// First match should be the best one
183-
SteamGridDBGameId = jsonSearchResponse.Data[0].Id
183+
SteamGridDBGameID = jsonSearchResponse.Data[0].ID
184184
}
185185

186-
if SteamGridDBGameId == -1 {
186+
if SteamGridDBGameID == -1 {
187187
return "", nil
188188
}
189189

190-
191190
// …and get the url of the top result.
192-
url = baseUrl + "/game/" + strconv.Itoa(SteamGridDBGameId) + filter
193-
responseBytes, err = SteamGridDBGetRequest(url, steamGridDBApiKey)
191+
url = baseURL + "/game/" + strconv.Itoa(SteamGridDBGameID) + filter
192+
responseBytes, err = steamGridDBGetRequest(url, steamGridDBApiKey)
194193
if err != nil {
195194
return "", err
196195
}
@@ -204,31 +203,31 @@ func getSteamGridDBImage(game *Game, artStyleExtensions []string, steamGridDBApi
204203
}
205204

206205
if jsonResponse.Success && len(jsonResponse.Data) >= 1 {
207-
return jsonResponse.Data[0].Url, nil
206+
return jsonResponse.Data[0].URL, nil
208207
}
209208
}
210209

211210
return "", nil
212211
}
213212

214-
const IGDBImageURL = "https://images.igdb.com/igdb/image/upload/t_720p/%v.jpg"
215-
const IGDBGameURL = "https://api-v3.igdb.com/games"
216-
const IGDBCoverURL = "https://api-v3.igdb.com/covers"
217-
const IGDBGameBody = `fields name,cover; search "%v";`
218-
const IGDBCoverBody = `fields image_id; where id = %v;`
213+
const igdbImageURL = "https://images.igdb.com/igdb/image/upload/t_720p/%v.jpg"
214+
const igdbGameURL = "https://api-v3.igdb.com/games"
215+
const igdbCoverURL = "https://api-v3.igdb.com/covers"
216+
const igdbGameBody = `fields name,cover; search "%v";`
217+
const igdbCoverBody = `fields image_id; where id = %v;`
219218

220-
type IGDBGame struct {
221-
Id int
219+
type igdbGame struct {
220+
ID int
222221
Cover int
223-
Name string
222+
Name string
224223
}
225224

226-
type IGDBCover struct {
227-
Id int
228-
Image_id string
225+
type igdbCover struct {
226+
ID int
227+
Image_ID string
229228
}
230229

231-
func IGDBPostRequest(url string, body string, IGDBApiKey string) ([]byte, error) {
230+
func igdbPostRequest(url string, body string, IGDBApiKey string) ([]byte, error) {
232231
client := &http.Client{}
233232
req, err := http.NewRequest("POST", url, strings.NewReader(body))
234233
req.Header.Add("user-key", IGDBApiKey)
@@ -252,12 +251,12 @@ func IGDBPostRequest(url string, body string, IGDBApiKey string) ([]byte, error)
252251
}
253252

254253
func getIGDBImage(gameName string, IGDBApiKey string) (string, error) {
255-
responseBytes, err := IGDBPostRequest(IGDBGameURL, fmt.Sprintf(IGDBGameBody, gameName), IGDBApiKey)
254+
responseBytes, err := igdbPostRequest(igdbGameURL, fmt.Sprintf(igdbGameBody, gameName), IGDBApiKey)
256255
if err != nil {
257256
return "", err
258257
}
259258

260-
var jsonGameResponse []IGDBGame
259+
var jsonGameResponse []igdbGame
261260
err = json.Unmarshal(responseBytes, &jsonGameResponse)
262261
if err != nil {
263262
return "", nil
@@ -267,19 +266,19 @@ func getIGDBImage(gameName string, IGDBApiKey string) (string, error) {
267266
return "", nil
268267
}
269268

270-
responseBytes, err = IGDBPostRequest(IGDBCoverURL, fmt.Sprintf(IGDBCoverBody, jsonGameResponse[0].Cover), IGDBApiKey)
269+
responseBytes, err = igdbPostRequest(igdbCoverURL, fmt.Sprintf(igdbCoverBody, jsonGameResponse[0].Cover), IGDBApiKey)
271270
if err != nil {
272271
return "", err
273272
}
274273

275-
var jsonCoverResponse []IGDBCover
274+
var jsonCoverResponse []igdbCover
276275
err = json.Unmarshal(responseBytes, &jsonCoverResponse)
277276
if err != nil {
278277
return "", nil
279278
}
280279

281280
if len(jsonCoverResponse) >= 1 {
282-
return fmt.Sprintf(IGDBImageURL, jsonCoverResponse[0].Image_id), nil
281+
return fmt.Sprintf(igdbImageURL, jsonCoverResponse[0].Image_ID), nil
283282
}
284283

285284
return "", nil
@@ -317,12 +316,12 @@ const steamCdnURLFormat = `cdn.akamai.steamstatic.com/steam/apps/%v/`
317316
func getImageAlternatives(game *Game, artStyle string, artStyleExtensions []string, skipSteam bool, steamGridDBApiKey string, steamGridFilter string, IGDBApiKey string, skipGoogle bool) (response *http.Response, from string, err error) {
318317
from = "steam server"
319318
if !skipSteam {
320-
response, err = tryDownload(fmt.Sprintf(akamaiURLFormat + artStyleExtensions[2], game.ID))
319+
response, err = tryDownload(fmt.Sprintf(akamaiURLFormat+artStyleExtensions[2], game.ID))
321320
if err == nil && response != nil {
322321
return
323322
}
324323

325-
response, err = tryDownload(fmt.Sprintf(steamCdnURLFormat + artStyleExtensions[2], game.ID))
324+
response, err = tryDownload(fmt.Sprintf(steamCdnURLFormat+artStyleExtensions[2], game.ID))
326325
if err == nil && response != nil {
327326
return
328327
}
@@ -400,13 +399,13 @@ func DownloadImage(gridDir string, game *Game, artStyle string, artStyleExtensio
400399
return "", err
401400
}
402401
imageSize := image.Bounds().Max
403-
if (artStyle == "Banner" && imageSize.X < imageSize.Y) {
402+
if artStyle == "Banner" && imageSize.X < imageSize.Y {
404403
return "", nil
405-
} else if (artStyle == "Cover" && imageSize.X > imageSize.Y) {
404+
} else if artStyle == "Cover" && imageSize.X > imageSize.Y {
406405
return "", nil
407406
}
408407

409-
game.ImageSource = from;
408+
game.ImageSource = from
410409

411410
game.CleanImageBytes = imageBytes
412411
return from, nil
@@ -415,8 +414,8 @@ func DownloadImage(gridDir string, game *Game, artStyle string, artStyleExtensio
415414
// Get game name from SteamDB as last resort.
416415
const steamDBFormat = `https://steamdb.info/app/%v`
417416

418-
func GetGameName(gameId string) string {
419-
response, err := tryDownload(fmt.Sprintf(steamDBFormat, gameId))
417+
func getGameName(gameID string) string {
418+
response, err := tryDownload(fmt.Sprintf(steamDBFormat, gameID))
420419
if err != nil || response == nil {
421420
return ""
422421
}
@@ -430,7 +429,7 @@ func GetGameName(gameId string) string {
430429
match := pattern.FindStringSubmatch(string(page))
431430
if match == nil || len(match) == 0 {
432431
return ""
433-
} else {
434-
return match[1]
435432
}
433+
434+
return match[1]
436435
}

games.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ func addNonSteamGames(user User, games map[string]*Game) {
118118
target := gameGroups[2]
119119
uniqueName := bytes.Join([][]byte{target, gameName}, []byte(""))
120120
// Does IEEE CRC32 of target concatenated with gameName. No idea why Steam chose this operation.
121-
gameID := strconv.FormatUint(uint64(crc32.ChecksumIEEE(uniqueName)) | 0x80000000, 10)
121+
gameID := strconv.FormatUint(uint64(crc32.ChecksumIEEE(uniqueName))|0x80000000, 10)
122122
game := Game{gameID, string(gameName), []string{}, "", nil, nil, "", true}
123123
games[gameID] = &game
124124

0 commit comments

Comments
 (0)