-
Notifications
You must be signed in to change notification settings - Fork 0
/
research.go
42 lines (39 loc) · 976 Bytes
/
research.go
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
package main
import (
"encoding/json"
"fmt"
"github.com/Henry-Sarabia/igdb"
"strings"
)
type ResearchedGame struct {
Id int `json:"id"`
Name string `json:"name"`
Cover string `json:"cover"`
}
func researchGames(gameName string, listSize int) string {
games, err := igdbClient.Games.Search(
strings.Replace(gameName, "²", "2", -1),
igdb.SetFields("name", "cover"),
igdb.SetLimit(listSize),
)
if err != nil {
panic(err.Error())
}
var research []ResearchedGame
for _, game := range games {
cover := "https://images.igdb.com/igdb/image/upload/t_cover_big_2x/nocover_qhhlj6.jpg"
if len(game.Cover.URL) > 0 {
cover = strings.Replace(fmt.Sprintf("https:%s", game.Cover.URL), "t_thumb", "t_cover_big_2x", -1)
}
research = append(research, ResearchedGame{
Id: game.ID,
Name: game.Name,
Cover: cover,
})
}
researchString, err := json.Marshal(research)
if err != nil {
panic(err.Error())
}
return string(researchString)
}