22 Commits

Author SHA1 Message Date
b99d06a2de u 2025-10-28 22:07:44 +11:00
4b6f488f59 feat(proto): Regenerate Go protobufs for new IGDB API types
Regenerated `proto/igdbapi.pb.go` to reflect updates in the IGDB API schema.
This update incorporates new API types, such as `AgeRatingContentDescriptionType` and its corresponding result type.

The regeneration was performed with:
- `protoc-gen-go` updated from `v1.36.5` to `v1.36.10`
- `protoc` updated from `v6.30.1` to `v6.32.1`
2025-10-28 20:12:19 +11:00
3df648929d u 2025-05-17 16:27:46 +10:00
5cb4ab4c61 u 2025-04-09 17:10:53 +10:00
ecf81bcf79 u 2025-04-07 22:28:43 +10:00
cf1f68c2d8 u 2025-04-07 22:25:58 +10:00
fb58744928 u 2025-04-07 22:23:36 +10:00
3d28910178 README 2025-04-06 13:24:02 +10:00
a583940e21 Create LICENSE 2025-04-06 13:21:34 +10:00
194e84c258 u 2025-04-06 03:33:02 +10:00
a8e650e4d7 u 2025-04-06 03:24:50 +10:00
f88ba544c2 README 2025-04-06 00:28:55 +11:00
d550f859a7 u 2025-04-06 00:28:00 +11:00
7f5a09098a u 2025-04-05 18:45:17 +11:00
35c27b28a3 u 2025-04-05 16:29:30 +11:00
dab30b4938 fix 2025-04-05 12:18:58 +11:00
4be44c4eb2 add limiter 2025-04-05 11:53:00 +11:00
e01d9805c6 README 2025-04-05 03:37:00 +11:00
76a3e977ba u 2025-04-05 03:30:18 +11:00
a0e24ca14b u 2025-04-05 03:14:04 +11:00
6ae7a18fd9 u 2025-04-05 03:10:28 +11:00
18dc9781b1 u 2025-04-05 02:42:09 +11:00
93 changed files with 6371 additions and 3681 deletions

2
.gitignore vendored
View File

@@ -1,2 +1,4 @@
*test.go
test/
.vscode/
.idea/

21
LICENSE Normal file
View File

@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2025 Nite
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

113
README.md
View File

@@ -1,14 +1,113 @@
# go-igdb
a go library to access IGDB API
A Go client library for the IGDB (Internet Game Database) API v4. This library provides a convenient way to interact with IGDB's protobuf-based API endpoints.
## Usage
## Features
- Full support for IGDB API v4 endpoints
- Protobuf-based communication for efficient data transfer
- Rate limiting support
- Automatic token management for Twitch authentication
- Retry mechanism for failed requests
- Optional FlareSolverr integration for handling Cloudflare protection
## Installation
```bash
go get github.com/bestnite/go-igdb
```
## Quick Start
```go
g := igdb.New("clientID", "clientSecret")
game, err := g.GetGame(325594)
if err != nil {
log.Fatal(err)
package main
import (
"log"
"github.com/bestnite/go-igdb"
)
func Test1(c *igdb.Client) {
game, err := c.Games.GetByID(1942)
if err != nil {
log.Fatal(err)
}
log.Printf("Name of game %d: %s\n", 1942, game.Name)
}
func Test2(c *igdb.Client) {
games, err := c.Games.GetByIDs([]uint64{119171, 119133})
if err != nil {
log.Fatal(err)
}
log.Printf("Names of games %d and %d: %s and %s\n", 119171, 119133, games[0].Name, games[1].Name)
}
func Test3(c *igdb.Client) {
total, err := c.Games.Count()
if err != nil {
log.Fatal(err)
}
log.Printf("Total number of games: %d\n", total)
}
func Test4(c *igdb.Client) {
games, err := c.Games.Paginated(0, 10)
if err != nil {
log.Fatal(err)
}
log.Printf("Names of ids 0 to 10 games:\n")
for _, game := range games {
log.Println(game.Name)
}
}
func Test5(c *igdb.Client) {
game, err := c.Games.Query("fields name,rating; sort rating desc; limit 1;")
if err != nil {
log.Fatalf("failed to get game: %s", err)
}
log.Printf("Name of first game with highest rating: %s\n", game[0].Name)
}
func Test6(c *igdb.Client) {
games, err := c.Games.Query("fields *; where rating > 70; limit 10;")
if err != nil {
panic(err)
}
log.Printf("Names of games with rating > 70 limit 10:\n")
for _, game := range games {
log.Println(game.Name)
}
}
func main() {
client := igdb.New("your-client-id", "your-client-secret")
Test1(client)
Test2(client)
Test3(client)
Test4(client)
Test5(client)
Test6(client)
}
fmt.Println(game.Name)
```
## Example Projects
- [igdb-database](https://github.com/bestnite/igdb-database)
## Dependencies
- [go-resty/resty](https://github.com/go-resty/resty)
- [google/protobuf](https://github.com/google/protobuf)
- [bestnite/go-flaresolverr](https://github.com/bestnite/go-flaresolverr)
- [PuerkitoBio/goquery](https://github.com/PuerkitoBio/goquery)
## Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
## License
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

142
client.go Normal file
View File

@@ -0,0 +1,142 @@
package igdb
import (
"context"
"fmt"
"strings"
"github.com/bestnite/go-flaresolverr"
"github.com/bestnite/go-igdb/endpoint"
"golang.org/x/time/rate"
"github.com/go-resty/resty/v2"
)
type Client struct {
clientID string
token *twitchToken
flaresolverr *flaresolverr.Flaresolverr
restyClient *resty.Client
limiter *rate.Limiter
AgeRatingCategories *endpoint.AgeRatingCategories
AgeRatingContentDescriptions *endpoint.AgeRatingContentDescriptions
AgeRatingContentDescriptionsV2 *endpoint.AgeRatingContentDescriptionsV2
AgeRatingOrganizations *endpoint.AgeRatingOrganizations
AgeRatings *endpoint.AgeRatings
AlternativeNames *endpoint.AlternativeNames
Artworks *endpoint.Artworks
CharacterGenders *endpoint.CharacterGenders
CharacterMugShots *endpoint.CharacterMugShots
Characters *endpoint.Characters
CharacterSpecies *endpoint.CharacterSpecies
CollectionMemberships *endpoint.CollectionMemberships
CollectionMembershipTypes *endpoint.CollectionMembershipTypes
CollectionRelations *endpoint.CollectionRelations
CollectionRelationTypes *endpoint.CollectionRelationTypes
Collections *endpoint.Collections
CollectionTypes *endpoint.CollectionTypes
Companies *endpoint.Companies
CompanyLogos *endpoint.CompanyLogos
CompanyStatuses *endpoint.CompanyStatuses
CompanyWebsites *endpoint.CompanyWebsites
Covers *endpoint.Covers
DateFormats *endpoint.DateFormats
EventLogos *endpoint.EventLogos
EventNetworks *endpoint.EventNetworks
Events *endpoint.Events
ExternalGames *endpoint.ExternalGames
ExternalGameSources *endpoint.ExternalGameSources
Franchises *endpoint.Franchises
GameEngineLogos *endpoint.GameEngineLogos
GameEngines *endpoint.GameEngines
GameLocalizations *endpoint.GameLocalizations
GameModes *endpoint.GameModes
GameReleaseFormats *endpoint.GameReleaseFormats
Games *endpoint.Games
GameStatuses *endpoint.GameStatuses
GameTimeToBeats *endpoint.GameTimeToBeats
GameTypes *endpoint.GameTypes
GameVersionFeatures *endpoint.GameVersionFeatures
GameVersionFeatureValues *endpoint.GameVersionFeatureValues
GameVersions *endpoint.GameVersions
GameVideos *endpoint.GameVideos
Genres *endpoint.Genres
InvolvedCompanies *endpoint.InvolvedCompanies
Keywords *endpoint.Keywords
Languages *endpoint.Languages
LanguageSupports *endpoint.LanguageSupports
LanguageSupportTypes *endpoint.LanguageSupportTypes
MultiplayerModes *endpoint.MultiplayerModes
NetworkTypes *endpoint.NetworkTypes
PlatformFamilies *endpoint.PlatformFamilies
PlatformLogos *endpoint.PlatformLogos
Platforms *endpoint.Platforms
PlatformTypes *endpoint.PlatformTypes
PlatformVersionCompanies *endpoint.PlatformVersionCompanies
PlatformVersionReleaseDates *endpoint.PlatformVersionReleaseDates
PlatformVersions *endpoint.PlatformVersions
PlatformWebsites *endpoint.PlatformWebsites
PlayerPerspectives *endpoint.PlayerPerspectives
PopularityPrimitives *endpoint.PopularityPrimitives
PopularityTypes *endpoint.PopularityTypes
Regions *endpoint.Regions
ReleaseDateRegions *endpoint.ReleaseDateRegions
ReleaseDates *endpoint.ReleaseDates
ReleaseDateStatuses *endpoint.ReleaseDateStatuses
Screenshots *endpoint.Screenshots
Search *endpoint.Search
Themes *endpoint.Themes
Webhooks *endpoint.Webhooks
Websites *endpoint.Websites
WebsiteTypes *endpoint.WebsiteTypes
}
func New(clientID, clientSecret string) *Client {
c := &Client{
clientID: clientID,
restyClient: NewRestyClient(),
token: newTwitchToken(clientID, clientSecret),
flaresolverr: nil,
limiter: rate.NewLimiter(rate.Limit(4), 4),
}
registerAllEndpoints(c)
return c
}
type RequestFunc func(method string, URL string, dataBody any) (*resty.Response, error)
func NewWithFlaresolverr(clientID, clientSecret string, f *flaresolverr.Flaresolverr) *Client {
c := New(clientID, clientSecret)
c.flaresolverr = f
return c
}
func (g *Client) Request(ctx context.Context, method string, URL string, dataBody any) (*resty.Response, error) {
err := g.limiter.Wait(ctx)
if err != nil {
return nil, fmt.Errorf("failed to get rate limiter token: %w", err)
}
t, err := g.token.GetToken(ctx)
if err != nil {
return nil, fmt.Errorf("failed to get twitch token: %w", err)
}
resp, err := g.restyClient.R().SetContext(ctx).SetBody(dataBody).SetHeaders(map[string]string{
"Client-ID": g.clientID,
"Authorization": "Bearer " + t,
"User-Agent": "",
"Content-Type": "text/plain",
}).Execute(strings.ToUpper(method), URL)
if resp.StatusCode() != 200 {
return nil, fmt.Errorf("failed to request, expected 200 but got: %v", resp.StatusCode())
}
if err != nil {
return nil, fmt.Errorf("failed to request: %s: %w", URL, err)
}
return resp, nil
}

View File

@@ -1,30 +0,0 @@
package igdb
import (
"errors"
"fmt"
"github/bestnite/go-igdb/constant"
pb "github/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
func (g *igdb) GetIGDBCompany(id uint64) (*pb.Company, error) {
query := fmt.Sprintf(`where id=%d; fields *;`, id)
resp, err := g.Request(constant.IGDBCompaniesURL, query)
if err != nil {
return nil, fmt.Errorf("failed to fetch IGDB company for ID %d: %w", id, err)
}
var data pb.CompanyResult
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
return nil, fmt.Errorf("failed to unmarshal IGDB companies response: %w", err)
}
if len(data.Companies) == 0 {
return nil, errors.New("company not found")
}
return data.Companies[0], nil
}

View File

@@ -1,12 +0,0 @@
package constant
const (
IGDBGameURL = "https://api.igdb.com/v4/games.pb"
IGDBCompaniesURL = "https://api.igdb.com/v4/companies.pb"
IGDBWebsitesURL = "https://api.igdb.com/v4/websites.pb"
IGDBExternalGameURL = "https://api.igdb.com/v4/external_games.pb"
IGDBPopularityURL = "https://api.igdb.com/v4/popularity_primitives.pb"
IGDBWebhookURL = "https://api.igdb.com/v4/%s/webhooks/"
IGDBWebSearchURL = "https://www.igdb.com/search"
TwitchAuthURL = "https://id.twitch.tv/oauth2/token"
)

View File

@@ -0,0 +1,43 @@
package endpoint
import (
"context"
"fmt"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
type AgeRatingCategories struct {
BaseEndpoint[pb.AgeRatingCategory]
}
func NewAgeRatingCategories(request RequestFunc) *AgeRatingCategories {
a := &AgeRatingCategories{
BaseEndpoint: BaseEndpoint[pb.AgeRatingCategory]{
endpointName: EPAgeRatingCategories,
request: request,
},
}
a.queryFunc = a.Query
return a
}
func (a *AgeRatingCategories) Query(ctx context.Context, query string) ([]*pb.AgeRatingCategory, error) {
resp, err := a.request(ctx, "POST", fmt.Sprintf("https://api.igdb.com/v4/%s.pb", a.endpointName), query)
if err != nil {
return nil, fmt.Errorf("failed to request: %w", err)
}
data := pb.AgeRatingCategoryResult{}
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
return nil, fmt.Errorf("failed to unmarshal: %w", err)
}
if len(data.Ageratingcategories) == 0 {
return nil, fmt.Errorf("no results: %s", query)
}
return data.Ageratingcategories, nil
}

View File

@@ -0,0 +1,43 @@
package endpoint
import (
"context"
"fmt"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
type AgeRatingContentDescriptions struct {
BaseEndpoint[pb.AgeRatingContentDescription]
}
func NewAgeRatingContentDescriptions(request RequestFunc) *AgeRatingContentDescriptions {
a := &AgeRatingContentDescriptions{
BaseEndpoint[pb.AgeRatingContentDescription]{
endpointName: EPAgeRatingContentDescriptions,
request: request,
},
}
a.queryFunc = a.Query
return a
}
func (a *AgeRatingContentDescriptions) Query(ctx context.Context, query string) ([]*pb.AgeRatingContentDescription, error) {
resp, err := a.request(ctx, "POST", fmt.Sprintf("https://api.igdb.com/v4/%s.pb", a.endpointName), query)
if err != nil {
return nil, fmt.Errorf("failed to request: %w", err)
}
data := pb.AgeRatingContentDescriptionResult{}
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
return nil, fmt.Errorf("failed to unmarshal: %w", err)
}
if len(data.Ageratingcontentdescriptions) == 0 {
return nil, fmt.Errorf("no results: %s", query)
}
return data.Ageratingcontentdescriptions, nil
}

View File

@@ -0,0 +1,43 @@
package endpoint
import (
"context"
"fmt"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
type AgeRatingContentDescriptionsV2 struct {
BaseEndpoint[pb.AgeRatingContentDescriptionV2]
}
func NewAgeRatingContentDescriptionsV2(request RequestFunc) *AgeRatingContentDescriptionsV2 {
a := &AgeRatingContentDescriptionsV2{
BaseEndpoint[pb.AgeRatingContentDescriptionV2]{
endpointName: EPAgeRatingContentDescriptionsV2,
request: request,
},
}
a.queryFunc = a.Query
return a
}
func (a *AgeRatingContentDescriptionsV2) Query(ctx context.Context, query string) ([]*pb.AgeRatingContentDescriptionV2, error) {
resp, err := a.request(ctx, "POST", fmt.Sprintf("https://api.igdb.com/v4/%s.pb", a.endpointName), query)
if err != nil {
return nil, fmt.Errorf("failed to request: %w", err)
}
data := pb.AgeRatingContentDescriptionV2Result{}
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
return nil, fmt.Errorf("failed to unmarshal: %w", err)
}
if len(data.Ageratingcontentdescriptionsv2) == 0 {
return nil, fmt.Errorf("no results: %s", query)
}
return data.Ageratingcontentdescriptionsv2, nil
}

View File

@@ -0,0 +1,43 @@
package endpoint
import (
"context"
"fmt"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
type AgeRatingOrganizations struct {
BaseEndpoint[pb.AgeRatingOrganization]
}
func NewAgeRatingOrganizations(request RequestFunc) *AgeRatingOrganizations {
a := &AgeRatingOrganizations{
BaseEndpoint[pb.AgeRatingOrganization]{
endpointName: EPAgeRatingOrganizations,
request: request,
},
}
a.queryFunc = a.Query
return a
}
func (a *AgeRatingOrganizations) Query(ctx context.Context, query string) ([]*pb.AgeRatingOrganization, error) {
resp, err := a.request(ctx, "POST", fmt.Sprintf("https://api.igdb.com/v4/%s.pb", a.endpointName), query)
if err != nil {
return nil, fmt.Errorf("failed to request: %w", err)
}
data := pb.AgeRatingOrganizationResult{}
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
return nil, fmt.Errorf("failed to unmarshal: %w", err)
}
if len(data.Ageratingorganizations) == 0 {
return nil, fmt.Errorf("no results: %s", query)
}
return data.Ageratingorganizations, nil
}

43
endpoint/age_ratings.go Normal file
View File

@@ -0,0 +1,43 @@
package endpoint
import (
"context"
"fmt"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
type AgeRatings struct {
BaseEndpoint[pb.AgeRating]
}
func NewAgeRatings(request RequestFunc) *AgeRatings {
a := &AgeRatings{
BaseEndpoint[pb.AgeRating]{
endpointName: EPAgeRatings,
request: request,
},
}
a.queryFunc = a.Query
return a
}
func (a *AgeRatings) Query(ctx context.Context, query string) ([]*pb.AgeRating, error) {
resp, err := a.request(ctx, "POST", fmt.Sprintf("https://api.igdb.com/v4/%s.pb", a.endpointName), query)
if err != nil {
return nil, fmt.Errorf("failed to request: %w", err)
}
data := pb.AgeRatingResult{}
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
return nil, fmt.Errorf("failed to unmarshal: %w", err)
}
if len(data.Ageratings) == 0 {
return nil, fmt.Errorf("no results: %s", query)
}
return data.Ageratings, nil
}

View File

@@ -0,0 +1,43 @@
package endpoint
import (
"context"
"fmt"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
type AlternativeNames struct {
BaseEndpoint[pb.AlternativeName]
}
func NewAlternativeNames(request RequestFunc) *AlternativeNames {
a := &AlternativeNames{
BaseEndpoint[pb.AlternativeName]{
endpointName: EPAlternativeNames,
request: request,
},
}
a.queryFunc = a.Query
return a
}
func (a *AlternativeNames) Query(ctx context.Context, query string) ([]*pb.AlternativeName, error) {
resp, err := a.request(ctx, "POST", fmt.Sprintf("https://api.igdb.com/v4/%s.pb", a.endpointName), query)
if err != nil {
return nil, fmt.Errorf("failed to request: %w", err)
}
data := pb.AlternativeNameResult{}
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
return nil, fmt.Errorf("failed to unmarshal: %w", err)
}
if len(data.Alternativenames) == 0 {
return nil, fmt.Errorf("no results: %s", query)
}
return data.Alternativenames, nil
}

43
endpoint/artworks.go Normal file
View File

@@ -0,0 +1,43 @@
package endpoint
import (
"context"
"fmt"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
type Artworks struct {
BaseEndpoint[pb.Artwork]
}
func NewArtworks(request RequestFunc) *Artworks {
a := &Artworks{
BaseEndpoint[pb.Artwork]{
endpointName: EPArtworks,
request: request,
},
}
a.queryFunc = a.Query
return a
}
func (a *Artworks) Query(ctx context.Context, query string) ([]*pb.Artwork, error) {
resp, err := a.request(ctx, "POST", fmt.Sprintf("https://api.igdb.com/v4/%s.pb", a.endpointName), query)
if err != nil {
return nil, fmt.Errorf("failed to request: %w", err)
}
data := pb.ArtworkResult{}
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
return nil, fmt.Errorf("failed to unmarshal: %w", err)
}
if len(data.Artworks) == 0 {
return nil, fmt.Errorf("no results: %s", query)
}
return data.Artworks, nil
}

97
endpoint/base.go Normal file
View File

@@ -0,0 +1,97 @@
package endpoint
import (
"context"
"fmt"
"strconv"
"strings"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
"github.com/go-resty/resty/v2"
)
type RequestFunc func(ctx context.Context, method string, URL string, dataBody any) (*resty.Response, error)
type BaseEndpoint[T any] struct {
request RequestFunc
endpointName Name
queryFunc func(context.Context, string) ([]*T, error)
}
func (b *BaseEndpoint[T]) GetEndpointName() Name {
return b.endpointName
}
func (b *BaseEndpoint[T]) Query(ctx context.Context, query string) ([]*T, error) {
if b.queryFunc == nil {
return nil, fmt.Errorf("query method must be implemented by specific endpoint")
}
return b.queryFunc(ctx, query)
}
func (b *BaseEndpoint[T]) GetByID(ctx context.Context, id uint64) (*T, error) {
res, err := b.Query(ctx, fmt.Sprintf("where id = %d; fields *;", id))
if err != nil {
return nil, err
}
if len(res) == 0 {
return nil, fmt.Errorf("no results")
}
return res[0], nil
}
func (b *BaseEndpoint[T]) GetByIDs(ctx context.Context, ids []uint64) ([]*T, error) {
if len(ids) == 0 {
return nil, fmt.Errorf("ids cant be empty")
}
batches := make([][]uint64, 0)
for i := 0; i < len(ids); i += 500 {
end := min(i+500, len(ids))
batches = append(batches, ids[i:end])
}
res := []*T{}
for _, batch := range batches {
builder := strings.Builder{}
for i, v := range batch {
if i > 0 {
builder.WriteByte(',')
}
builder.WriteString(strconv.FormatUint(v, 10))
}
batchRes, err := b.Query(ctx, fmt.Sprintf("where id = (%s); fields *; limit 500;", builder.String()))
if err != nil {
return nil, err
}
res = append(res, batchRes...)
}
return res, nil
}
func (b *BaseEndpoint[T]) Count(ctx context.Context) (uint64, error) {
resp, err := b.request(ctx, "POST", fmt.Sprintf("https://api.igdb.com/v4/%s/count.pb", b.endpointName), "")
if err != nil {
return 0, fmt.Errorf("failed to request: %w", err)
}
var res pb.Count
if err = proto.Unmarshal(resp.Body(), &res); err != nil {
return 0, fmt.Errorf("failed to unmarshal: %w", err)
}
return uint64(res.Count), nil
}
func (b *BaseEndpoint[T]) Paginated(ctx context.Context, offset, limit uint64) ([]*T, error) {
return b.Query(ctx, fmt.Sprintf("offset %d; limit %d; fields *; sort id asc;", offset, limit))
}
type EntityEndpoint[T any] interface {
GetEndpointName() Name
Query(context.Context, string) ([]*T, error)
GetByID(context.Context, uint64) (*T, error)
GetByIDs(context.Context, []uint64) ([]*T, error)
Count(context.Context) (uint64, error)
Paginated(context.Context, uint64, uint64) ([]*T, error)
}

View File

@@ -0,0 +1,43 @@
package endpoint
import (
"context"
"fmt"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
type CharacterGenders struct {
BaseEndpoint[pb.CharacterGender]
}
func NewCharacterGenders(request RequestFunc) *CharacterGenders {
a := &CharacterGenders{
BaseEndpoint[pb.CharacterGender]{
endpointName: EPCharacterGenders,
request: request,
},
}
a.queryFunc = a.Query
return a
}
func (a *CharacterGenders) Query(ctx context.Context, query string) ([]*pb.CharacterGender, error) {
resp, err := a.request(ctx, "POST", fmt.Sprintf("https://api.igdb.com/v4/%s.pb", a.endpointName), query)
if err != nil {
return nil, fmt.Errorf("failed to request: %w", err)
}
data := pb.CharacterGenderResult{}
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
return nil, fmt.Errorf("failed to unmarshal: %w", err)
}
if len(data.Charactergenders) == 0 {
return nil, fmt.Errorf("no results: %s", query)
}
return data.Charactergenders, nil
}

View File

@@ -0,0 +1,43 @@
package endpoint
import (
"context"
"fmt"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
type CharacterMugShots struct {
BaseEndpoint[pb.CharacterMugShot]
}
func NewCharacterMugShots(request RequestFunc) *CharacterMugShots {
a := &CharacterMugShots{
BaseEndpoint[pb.CharacterMugShot]{
endpointName: EPCharacterMugShots,
request: request,
},
}
a.queryFunc = a.Query
return a
}
func (a *CharacterMugShots) Query(ctx context.Context, query string) ([]*pb.CharacterMugShot, error) {
resp, err := a.request(ctx, "POST", fmt.Sprintf("https://api.igdb.com/v4/%s.pb", a.endpointName), query)
if err != nil {
return nil, fmt.Errorf("failed to request: %w", err)
}
data := pb.CharacterMugShotResult{}
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
return nil, fmt.Errorf("failed to unmarshal: %w", err)
}
if len(data.Charactermugshots) == 0 {
return nil, fmt.Errorf("no results: %s", query)
}
return data.Charactermugshots, nil
}

View File

@@ -0,0 +1,43 @@
package endpoint
import (
"context"
"fmt"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
type CharacterSpecies struct {
BaseEndpoint[pb.CharacterSpecie]
}
func NewCharacterSpecies(request RequestFunc) *CharacterSpecies {
a := &CharacterSpecies{
BaseEndpoint[pb.CharacterSpecie]{
endpointName: EPCharacterSpecies,
request: request,
},
}
a.queryFunc = a.Query
return a
}
func (a *CharacterSpecies) Query(ctx context.Context, query string) ([]*pb.CharacterSpecie, error) {
resp, err := a.request(ctx, "POST", fmt.Sprintf("https://api.igdb.com/v4/%s.pb", a.endpointName), query)
if err != nil {
return nil, fmt.Errorf("failed to request: %w", err)
}
data := pb.CharacterSpecieResult{}
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
return nil, fmt.Errorf("failed to unmarshal: %w", err)
}
if len(data.Characterspecies) == 0 {
return nil, fmt.Errorf("no results: %s", query)
}
return data.Characterspecies, nil
}

43
endpoint/characters.go Normal file
View File

@@ -0,0 +1,43 @@
package endpoint
import (
"context"
"fmt"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
type Characters struct {
BaseEndpoint[pb.Character]
}
func NewCharacters(request RequestFunc) *Characters {
a := &Characters{
BaseEndpoint[pb.Character]{
endpointName: EPCharacters,
request: request,
},
}
a.queryFunc = a.Query
return a
}
func (a *Characters) Query(ctx context.Context, query string) ([]*pb.Character, error) {
resp, err := a.request(ctx, "POST", fmt.Sprintf("https://api.igdb.com/v4/%s.pb", a.endpointName), query)
if err != nil {
return nil, fmt.Errorf("failed to request: %w", err)
}
data := pb.CharacterResult{}
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
return nil, fmt.Errorf("failed to unmarshal: %w", err)
}
if len(data.Characters) == 0 {
return nil, fmt.Errorf("no results: %s", query)
}
return data.Characters, nil
}

View File

@@ -0,0 +1,43 @@
package endpoint
import (
"context"
"fmt"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
type CollectionMembershipTypes struct {
BaseEndpoint[pb.CollectionMembershipType]
}
func NewCollectionMembershipTypes(request RequestFunc) *CollectionMembershipTypes {
a := &CollectionMembershipTypes{
BaseEndpoint[pb.CollectionMembershipType]{
endpointName: EPCollectionMembershipTypes,
request: request,
},
}
a.queryFunc = a.Query
return a
}
func (a *CollectionMembershipTypes) Query(ctx context.Context, query string) ([]*pb.CollectionMembershipType, error) {
resp, err := a.request(ctx, "POST", fmt.Sprintf("https://api.igdb.com/v4/%s.pb", a.endpointName), query)
if err != nil {
return nil, fmt.Errorf("failed to request: %w", err)
}
data := pb.CollectionMembershipTypeResult{}
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
return nil, fmt.Errorf("failed to unmarshal: %w", err)
}
if len(data.Collectionmembershiptypes) == 0 {
return nil, fmt.Errorf("no results: %s", query)
}
return data.Collectionmembershiptypes, nil
}

View File

@@ -0,0 +1,43 @@
package endpoint
import (
"context"
"fmt"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
type CollectionMemberships struct {
BaseEndpoint[pb.CollectionMembership]
}
func NewCollectionMemberships(request RequestFunc) *CollectionMemberships {
a := &CollectionMemberships{
BaseEndpoint[pb.CollectionMembership]{
endpointName: EPCollectionMemberships,
request: request,
},
}
a.queryFunc = a.Query
return a
}
func (a *CollectionMemberships) Query(ctx context.Context, query string) ([]*pb.CollectionMembership, error) {
resp, err := a.request(ctx, "POST", fmt.Sprintf("https://api.igdb.com/v4/%s.pb", a.endpointName), query)
if err != nil {
return nil, fmt.Errorf("failed to request: %w", err)
}
data := pb.CollectionMembershipResult{}
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
return nil, fmt.Errorf("failed to unmarshal: %w", err)
}
if len(data.Collectionmemberships) == 0 {
return nil, fmt.Errorf("no results: %s", query)
}
return data.Collectionmemberships, nil
}

View File

@@ -0,0 +1,43 @@
package endpoint
import (
"context"
"fmt"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
type CollectionRelationTypes struct {
BaseEndpoint[pb.CollectionRelationType]
}
func NewCollectionRelationTypes(request RequestFunc) *CollectionRelationTypes {
a := &CollectionRelationTypes{
BaseEndpoint[pb.CollectionRelationType]{
endpointName: EPCollectionRelationTypes,
request: request,
},
}
a.queryFunc = a.Query
return a
}
func (a *CollectionRelationTypes) Query(ctx context.Context, query string) ([]*pb.CollectionRelationType, error) {
resp, err := a.request(ctx, "POST", fmt.Sprintf("https://api.igdb.com/v4/%s.pb", a.endpointName), query)
if err != nil {
return nil, fmt.Errorf("failed to request: %w", err)
}
data := pb.CollectionRelationTypeResult{}
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
return nil, fmt.Errorf("failed to unmarshal: %w", err)
}
if len(data.Collectionrelationtypes) == 0 {
return nil, fmt.Errorf("no results: %s", query)
}
return data.Collectionrelationtypes, nil
}

View File

@@ -0,0 +1,43 @@
package endpoint
import (
"context"
"fmt"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
type CollectionRelations struct {
BaseEndpoint[pb.CollectionRelation]
}
func NewCollectionRelations(request RequestFunc) *CollectionRelations {
a := &CollectionRelations{
BaseEndpoint[pb.CollectionRelation]{
endpointName: EPCollectionRelations,
request: request,
},
}
a.queryFunc = a.Query
return a
}
func (a *CollectionRelations) Query(ctx context.Context, query string) ([]*pb.CollectionRelation, error) {
resp, err := a.request(ctx, "POST", fmt.Sprintf("https://api.igdb.com/v4/%s.pb", a.endpointName), query)
if err != nil {
return nil, fmt.Errorf("failed to request: %w", err)
}
data := pb.CollectionRelationResult{}
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
return nil, fmt.Errorf("failed to unmarshal: %w", err)
}
if len(data.Collectionrelations) == 0 {
return nil, fmt.Errorf("no results: %s", query)
}
return data.Collectionrelations, nil
}

View File

@@ -0,0 +1,43 @@
package endpoint
import (
"context"
"fmt"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
type CollectionTypes struct {
BaseEndpoint[pb.CollectionType]
}
func NewCollectionTypes(request RequestFunc) *CollectionTypes {
a := &CollectionTypes{
BaseEndpoint[pb.CollectionType]{
endpointName: EPCollectionTypes,
request: request,
},
}
a.queryFunc = a.Query
return a
}
func (a *CollectionTypes) Query(ctx context.Context, query string) ([]*pb.CollectionType, error) {
resp, err := a.request(ctx, "POST", fmt.Sprintf("https://api.igdb.com/v4/%s.pb", a.endpointName), query)
if err != nil {
return nil, fmt.Errorf("failed to request: %w", err)
}
data := pb.CollectionTypeResult{}
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
return nil, fmt.Errorf("failed to unmarshal: %w", err)
}
if len(data.Collectiontypes) == 0 {
return nil, fmt.Errorf("no results: %s", query)
}
return data.Collectiontypes, nil
}

43
endpoint/collections.go Normal file
View File

@@ -0,0 +1,43 @@
package endpoint
import (
"context"
"fmt"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
type Collections struct {
BaseEndpoint[pb.Collection]
}
func NewCollections(request RequestFunc) *Collections {
a := &Collections{
BaseEndpoint[pb.Collection]{
endpointName: EPCollections,
request: request,
},
}
a.queryFunc = a.Query
return a
}
func (a *Collections) Query(ctx context.Context, query string) ([]*pb.Collection, error) {
resp, err := a.request(ctx, "POST", fmt.Sprintf("https://api.igdb.com/v4/%s.pb", a.endpointName), query)
if err != nil {
return nil, fmt.Errorf("failed to request: %w", err)
}
data := pb.CollectionResult{}
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
return nil, fmt.Errorf("failed to unmarshal: %w", err)
}
if len(data.Collections) == 0 {
return nil, fmt.Errorf("no results: %s", query)
}
return data.Collections, nil
}

44
endpoint/companies.go Normal file
View File

@@ -0,0 +1,44 @@
package endpoint
import (
"context"
"errors"
"fmt"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
type Companies struct {
BaseEndpoint[pb.Company]
}
func NewCompanies(request RequestFunc) *Companies {
a := &Companies{
BaseEndpoint[pb.Company]{
endpointName: EPCompanies,
request: request,
},
}
a.queryFunc = a.Query
return a
}
func (a *Companies) Query(ctx context.Context, query string) ([]*pb.Company, error) {
resp, err := a.request(ctx, "POST", fmt.Sprintf("https://api.igdb.com/v4/%s.pb", a.endpointName), query)
if err != nil {
return nil, fmt.Errorf("failed to request: %w", err)
}
data := pb.CompanyResult{}
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
return nil, fmt.Errorf("failed to unmarshal: %w", err)
}
if len(data.Companies) == 0 {
return nil, errors.New("no results")
}
return data.Companies, nil
}

43
endpoint/company_logos.go Normal file
View File

@@ -0,0 +1,43 @@
package endpoint
import (
"context"
"fmt"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
type CompanyLogos struct {
BaseEndpoint[pb.CompanyLogo]
}
func NewCompanyLogos(request RequestFunc) *CompanyLogos {
a := &CompanyLogos{
BaseEndpoint[pb.CompanyLogo]{
endpointName: EPCompanyLogos,
request: request,
},
}
a.queryFunc = a.Query
return a
}
func (a *CompanyLogos) Query(ctx context.Context, query string) ([]*pb.CompanyLogo, error) {
resp, err := a.request(ctx, "POST", fmt.Sprintf("https://api.igdb.com/v4/%s.pb", a.endpointName), query)
if err != nil {
return nil, fmt.Errorf("failed to request: %w", err)
}
data := pb.CompanyLogoResult{}
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
return nil, fmt.Errorf("failed to unmarshal: %w", err)
}
if len(data.Companylogos) == 0 {
return nil, fmt.Errorf("no results: %s", query)
}
return data.Companylogos, nil
}

View File

@@ -0,0 +1,43 @@
package endpoint
import (
"context"
"fmt"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
type CompanyStatuses struct {
BaseEndpoint[pb.CompanyStatus]
}
func NewCompanyStatuses(request RequestFunc) *CompanyStatuses {
a := &CompanyStatuses{
BaseEndpoint[pb.CompanyStatus]{
endpointName: EPCompanyStatuses,
request: request,
},
}
a.queryFunc = a.Query
return a
}
func (a *CompanyStatuses) Query(ctx context.Context, query string) ([]*pb.CompanyStatus, error) {
resp, err := a.request(ctx, "POST", fmt.Sprintf("https://api.igdb.com/v4/%s.pb", a.endpointName), query)
if err != nil {
return nil, fmt.Errorf("failed to request: %w", err)
}
data := pb.CompanyStatusResult{}
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
return nil, fmt.Errorf("failed to unmarshal: %w", err)
}
if len(data.Companystatuses) == 0 {
return nil, fmt.Errorf("no results: %s", query)
}
return data.Companystatuses, nil
}

View File

@@ -0,0 +1,43 @@
package endpoint
import (
"context"
"fmt"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
type CompanyWebsites struct {
BaseEndpoint[pb.CompanyWebsite]
}
func NewCompanyWebsites(request RequestFunc) *CompanyWebsites {
a := &CompanyWebsites{
BaseEndpoint[pb.CompanyWebsite]{
endpointName: EPCompanyWebsites,
request: request,
},
}
a.queryFunc = a.Query
return a
}
func (a *CompanyWebsites) Query(ctx context.Context, query string) ([]*pb.CompanyWebsite, error) {
resp, err := a.request(ctx, "POST", fmt.Sprintf("https://api.igdb.com/v4/%s.pb", a.endpointName), query)
if err != nil {
return nil, fmt.Errorf("failed to request: %w", err)
}
data := pb.CompanyWebsiteResult{}
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
return nil, fmt.Errorf("failed to unmarshal: %w", err)
}
if len(data.Companywebsites) == 0 {
return nil, fmt.Errorf("no results: %s", query)
}
return data.Companywebsites, nil
}

43
endpoint/covers.go Normal file
View File

@@ -0,0 +1,43 @@
package endpoint
import (
"context"
"fmt"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
type Covers struct {
BaseEndpoint[pb.Cover]
}
func NewCovers(request RequestFunc) *Covers {
a := &Covers{
BaseEndpoint[pb.Cover]{
endpointName: EPCovers,
request: request,
},
}
a.queryFunc = a.Query
return a
}
func (a *Covers) Query(ctx context.Context, query string) ([]*pb.Cover, error) {
resp, err := a.request(ctx, "POST", fmt.Sprintf("https://api.igdb.com/v4/%s.pb", a.endpointName), query)
if err != nil {
return nil, fmt.Errorf("failed to request: %w", err)
}
data := pb.CoverResult{}
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
return nil, fmt.Errorf("failed to unmarshal: %w", err)
}
if len(data.Covers) == 0 {
return nil, fmt.Errorf("no results: %s", query)
}
return data.Covers, nil
}

43
endpoint/date_formats.go Normal file
View File

@@ -0,0 +1,43 @@
package endpoint
import (
"context"
"fmt"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
type DateFormats struct {
BaseEndpoint[pb.DateFormat]
}
func NewDateFormats(request RequestFunc) *DateFormats {
a := &DateFormats{
BaseEndpoint[pb.DateFormat]{
endpointName: EPDateFormats,
request: request,
},
}
a.queryFunc = a.Query
return a
}
func (a *DateFormats) Query(ctx context.Context, query string) ([]*pb.DateFormat, error) {
resp, err := a.request(ctx, "POST", fmt.Sprintf("https://api.igdb.com/v4/%s.pb", a.endpointName), query)
if err != nil {
return nil, fmt.Errorf("failed to request: %w", err)
}
data := pb.DateFormatResult{}
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
return nil, fmt.Errorf("failed to unmarshal: %w", err)
}
if len(data.Dateformats) == 0 {
return nil, fmt.Errorf("no results: %s", query)
}
return data.Dateformats, nil
}

151
endpoint/endpoint_name.go Normal file
View File

@@ -0,0 +1,151 @@
package endpoint
type Name string
var (
EPAgeRatingCategories Name = "age_rating_categories"
EPAgeRatingContentDescriptions Name = "age_rating_content_descriptions"
EPAgeRatingContentDescriptionsV2 Name = "age_rating_content_descriptions_v2"
EPAgeRatingOrganizations Name = "age_rating_organizations"
EPAgeRatings Name = "age_ratings"
EPAlternativeNames Name = "alternative_names"
EPArtworks Name = "artworks"
EPCharacterGenders Name = "character_genders"
EPCharacterMugShots Name = "character_mug_shots"
EPCharacters Name = "characters"
EPCharacterSpecies Name = "character_species"
EPCollectionMemberships Name = "collection_memberships"
EPCollectionMembershipTypes Name = "collection_membership_types"
EPCollectionRelations Name = "collection_relations"
EPCollectionRelationTypes Name = "collection_relation_types"
EPCollections Name = "collections"
EPCollectionTypes Name = "collection_types"
EPCompanies Name = "companies"
EPCompanyLogos Name = "company_logos"
EPCompanyStatuses Name = "company_statuses"
EPCompanyWebsites Name = "company_websites"
EPCovers Name = "covers"
EPDateFormats Name = "date_formats"
EPEventLogos Name = "event_logos"
EPEventNetworks Name = "event_networks"
EPEvents Name = "events"
EPExternalGames Name = "external_games"
EPExternalGameSources Name = "external_game_sources"
EPFranchises Name = "franchises"
EPGameEngineLogos Name = "game_engine_logos"
EPGameEngines Name = "game_engines"
EPGameLocalizations Name = "game_localizations"
EPGameModes Name = "game_modes"
EPGameReleaseFormats Name = "game_release_formats"
EPGames Name = "games"
EPGameStatuses Name = "game_statuses"
EPGameTimeToBeats Name = "game_time_to_beats"
EPGameTypes Name = "game_types"
EPGameVersionFeatures Name = "game_version_features"
EPGameVersionFeatureValues Name = "game_version_feature_values"
EPGameVersions Name = "game_versions"
EPGameVideos Name = "game_videos"
EPGenres Name = "genres"
EPInvolvedCompanies Name = "involved_companies"
EPKeywords Name = "keywords"
EPLanguages Name = "languages"
EPLanguageSupports Name = "language_supports"
EPLanguageSupportTypes Name = "language_support_types"
EPMultiplayerModes Name = "multiplayer_modes"
EPNetworkTypes Name = "network_types"
EPPlatformFamilies Name = "platform_families"
EPPlatformLogos Name = "platform_logos"
EPPlatforms Name = "platforms"
EPPlatformTypes Name = "platform_types"
EPPlatformVersionCompanies Name = "platform_version_companies"
EPPlatformVersionReleaseDates Name = "platform_version_release_dates"
EPPlatformVersions Name = "platform_versions"
EPPlatformWebsites Name = "platform_websites"
EPPlayerPerspectives Name = "player_perspectives"
EPPopularityPrimitives Name = "popularity_primitives"
EPPopularityTypes Name = "popularity_types"
EPRegions Name = "regions"
EPReleaseDateRegions Name = "release_date_regions"
EPReleaseDates Name = "release_dates"
EPReleaseDateStatuses Name = "release_date_statuses"
EPScreenshots Name = "screenshots"
EPSearch Name = "search"
EPThemes Name = "themes"
EPWebhooks Name = "webhooks"
EPWebsites Name = "websites"
EPWebsiteTypes Name = "website_types"
)
var AllNames = []Name{
EPAgeRatingCategories,
EPAgeRatingContentDescriptions,
EPAgeRatingContentDescriptionsV2,
EPAgeRatingOrganizations,
EPAgeRatings,
EPAlternativeNames,
EPArtworks,
EPCharacterGenders,
EPCharacterMugShots,
EPCharacters,
EPCharacterSpecies,
EPCollectionMemberships,
EPCollectionMembershipTypes,
EPCollectionRelations,
EPCollectionRelationTypes,
EPCollections,
EPCollectionTypes,
EPCompanies,
EPCompanyLogos,
EPCompanyStatuses,
EPCompanyWebsites,
EPCovers,
EPDateFormats,
EPEventLogos,
EPEventNetworks,
EPEvents,
EPExternalGames,
EPExternalGameSources,
EPFranchises,
EPGameEngineLogos,
EPGameEngines,
EPGameLocalizations,
EPGameModes,
EPGameReleaseFormats,
EPGames,
EPGameStatuses,
EPGameTimeToBeats,
EPGameTypes,
EPGameVersionFeatures,
EPGameVersionFeatureValues,
EPGameVersions,
EPGameVideos,
EPGenres,
EPInvolvedCompanies,
EPKeywords,
EPLanguages,
EPLanguageSupports,
EPLanguageSupportTypes,
EPMultiplayerModes,
EPNetworkTypes,
EPPlatformFamilies,
EPPlatformLogos,
EPPlatforms,
EPPlatformTypes,
EPPlatformVersionCompanies,
EPPlatformVersionReleaseDates,
EPPlatformVersions,
EPPlatformWebsites,
EPPlayerPerspectives,
EPPopularityPrimitives,
EPPopularityTypes,
EPRegions,
EPReleaseDateRegions,
EPReleaseDates,
EPReleaseDateStatuses,
EPScreenshots,
EPSearch,
EPThemes,
EPWebhooks,
EPWebsites,
EPWebsiteTypes,
}

43
endpoint/event_logos.go Normal file
View File

@@ -0,0 +1,43 @@
package endpoint
import (
"context"
"fmt"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
type EventLogos struct {
BaseEndpoint[pb.EventLogo]
}
func NewEventLogos(request RequestFunc) *EventLogos {
a := &EventLogos{
BaseEndpoint[pb.EventLogo]{
endpointName: EPEventLogos,
request: request,
},
}
a.queryFunc = a.Query
return a
}
func (a *EventLogos) Query(ctx context.Context, query string) ([]*pb.EventLogo, error) {
resp, err := a.request(ctx, "POST", fmt.Sprintf("https://api.igdb.com/v4/%s.pb", a.endpointName), query)
if err != nil {
return nil, fmt.Errorf("failed to request: %w", err)
}
data := pb.EventLogoResult{}
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
return nil, fmt.Errorf("failed to unmarshal: %w", err)
}
if len(data.Eventlogos) == 0 {
return nil, fmt.Errorf("no results: %s", query)
}
return data.Eventlogos, nil
}

View File

@@ -0,0 +1,43 @@
package endpoint
import (
"context"
"fmt"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
type EventNetworks struct {
BaseEndpoint[pb.EventNetwork]
}
func NewEventNetworks(request RequestFunc) *EventNetworks {
a := &EventNetworks{
BaseEndpoint[pb.EventNetwork]{
endpointName: EPEventNetworks,
request: request,
},
}
a.queryFunc = a.Query
return a
}
func (a *EventNetworks) Query(ctx context.Context, query string) ([]*pb.EventNetwork, error) {
resp, err := a.request(ctx, "POST", fmt.Sprintf("https://api.igdb.com/v4/%s.pb", a.endpointName), query)
if err != nil {
return nil, fmt.Errorf("failed to request: %w", err)
}
data := pb.EventNetworkResult{}
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
return nil, fmt.Errorf("failed to unmarshal: %w", err)
}
if len(data.Eventnetworks) == 0 {
return nil, fmt.Errorf("no results: %s", query)
}
return data.Eventnetworks, nil
}

43
endpoint/events.go Normal file
View File

@@ -0,0 +1,43 @@
package endpoint
import (
"context"
"fmt"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
type Events struct {
BaseEndpoint[pb.Event]
}
func NewEvents(request RequestFunc) *Events {
a := &Events{
BaseEndpoint[pb.Event]{
endpointName: EPEvents,
request: request,
},
}
a.queryFunc = a.Query
return a
}
func (a *Events) Query(ctx context.Context, query string) ([]*pb.Event, error) {
resp, err := a.request(ctx, "POST", fmt.Sprintf("https://api.igdb.com/v4/%s.pb", a.endpointName), query)
if err != nil {
return nil, fmt.Errorf("failed to request: %w", err)
}
data := pb.EventResult{}
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
return nil, fmt.Errorf("failed to unmarshal: %w", err)
}
if len(data.Events) == 0 {
return nil, fmt.Errorf("no results: %s", query)
}
return data.Events, nil
}

View File

@@ -0,0 +1,43 @@
package endpoint
import (
"context"
"fmt"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
type ExternalGameSources struct {
BaseEndpoint[pb.ExternalGameSource]
}
func NewExternalGameSources(request RequestFunc) *ExternalGameSources {
a := &ExternalGameSources{
BaseEndpoint[pb.ExternalGameSource]{
endpointName: EPExternalGameSources,
request: request,
},
}
a.queryFunc = a.Query
return a
}
func (a *ExternalGameSources) Query(ctx context.Context, query string) ([]*pb.ExternalGameSource, error) {
resp, err := a.request(ctx, "POST", fmt.Sprintf("https://api.igdb.com/v4/%s.pb", a.endpointName), query)
if err != nil {
return nil, fmt.Errorf("failed to request: %w", err)
}
data := pb.ExternalGameSourceResult{}
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
return nil, fmt.Errorf("failed to unmarshal: %w", err)
}
if len(data.Externalgamesources) == 0 {
return nil, fmt.Errorf("no results: %s", query)
}
return data.Externalgamesources, nil
}

View File

@@ -0,0 +1,43 @@
package endpoint
import (
"context"
"fmt"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
type ExternalGames struct {
BaseEndpoint[pb.ExternalGame]
}
func NewExternalGames(request RequestFunc) *ExternalGames {
a := &ExternalGames{
BaseEndpoint[pb.ExternalGame]{
endpointName: EPExternalGames,
request: request,
},
}
a.queryFunc = a.Query
return a
}
func (a *ExternalGames) Query(ctx context.Context, query string) ([]*pb.ExternalGame, error) {
resp, err := a.request(ctx, "POST", fmt.Sprintf("https://api.igdb.com/v4/%s.pb", a.endpointName), query)
if err != nil {
return nil, fmt.Errorf("failed to request: %w", err)
}
data := pb.ExternalGameResult{}
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
return nil, fmt.Errorf("failed to unmarshal: %w", err)
}
if len(data.Externalgames) == 0 {
return nil, fmt.Errorf("no results: %s", query)
}
return data.Externalgames, nil
}

43
endpoint/franchises.go Normal file
View File

@@ -0,0 +1,43 @@
package endpoint
import (
"context"
"fmt"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
type Franchises struct {
BaseEndpoint[pb.Franchise]
}
func NewFranchises(request RequestFunc) *Franchises {
a := &Franchises{
BaseEndpoint: BaseEndpoint[pb.Franchise]{
endpointName: EPFranchises,
request: request,
},
}
a.queryFunc = a.Query
return a
}
func (a *Franchises) Query(ctx context.Context, query string) ([]*pb.Franchise, error) {
resp, err := a.request(ctx, "POST", fmt.Sprintf("https://api.igdb.com/v4/%s.pb", a.endpointName), query)
if err != nil {
return nil, fmt.Errorf("failed to request: %w", err)
}
data := pb.FranchiseResult{}
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
return nil, fmt.Errorf("failed to unmarshal: %w", err)
}
if len(data.Franchises) == 0 {
return nil, fmt.Errorf("no results: %s", query)
}
return data.Franchises, nil
}

View File

@@ -0,0 +1,43 @@
package endpoint
import (
"context"
"fmt"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
type GameEngineLogos struct {
BaseEndpoint[pb.GameEngineLogo]
}
func NewGameEngineLogos(request RequestFunc) *GameEngineLogos {
a := &GameEngineLogos{
BaseEndpoint[pb.GameEngineLogo]{
endpointName: EPGameEngineLogos,
request: request,
},
}
a.queryFunc = a.Query
return a
}
func (a *GameEngineLogos) Query(ctx context.Context, query string) ([]*pb.GameEngineLogo, error) {
resp, err := a.request(ctx, "POST", fmt.Sprintf("https://api.igdb.com/v4/%s.pb", a.endpointName), query)
if err != nil {
return nil, fmt.Errorf("failed to request: %w", err)
}
data := pb.GameEngineLogoResult{}
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
return nil, fmt.Errorf("failed to unmarshal: %w", err)
}
if len(data.Gameenginelogos) == 0 {
return nil, fmt.Errorf("no results: %s", query)
}
return data.Gameenginelogos, nil
}

43
endpoint/game_engines.go Normal file
View File

@@ -0,0 +1,43 @@
package endpoint
import (
"context"
"fmt"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
type GameEngines struct {
BaseEndpoint[pb.GameEngine]
}
func NewGameEngines(request RequestFunc) *GameEngines {
a := &GameEngines{
BaseEndpoint: BaseEndpoint[pb.GameEngine]{
endpointName: EPGameEngines,
request: request,
},
}
a.queryFunc = a.Query
return a
}
func (a *GameEngines) Query(ctx context.Context, query string) ([]*pb.GameEngine, error) {
resp, err := a.request(ctx, "POST", fmt.Sprintf("https://api.igdb.com/v4/%s.pb", a.endpointName), query)
if err != nil {
return nil, fmt.Errorf("failed to request: %w", err)
}
data := pb.GameEngineResult{}
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
return nil, fmt.Errorf("failed to unmarshal: %w", err)
}
if len(data.Gameengines) == 0 {
return nil, fmt.Errorf("no results: %s", query)
}
return data.Gameengines, nil
}

View File

@@ -0,0 +1,43 @@
package endpoint
import (
"context"
"fmt"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
type GameLocalizations struct {
BaseEndpoint[pb.GameLocalization]
}
func NewGameLocalizations(request RequestFunc) *GameLocalizations {
a := &GameLocalizations{
BaseEndpoint: BaseEndpoint[pb.GameLocalization]{
endpointName: EPGameLocalizations,
request: request,
},
}
a.queryFunc = a.Query
return a
}
func (a *GameLocalizations) Query(ctx context.Context, query string) ([]*pb.GameLocalization, error) {
resp, err := a.request(ctx, "POST", fmt.Sprintf("https://api.igdb.com/v4/%s.pb", a.endpointName), query)
if err != nil {
return nil, fmt.Errorf("failed to request: %w", err)
}
data := pb.GameLocalizationResult{}
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
return nil, fmt.Errorf("failed to unmarshal: %w", err)
}
if len(data.Gamelocalizations) == 0 {
return nil, fmt.Errorf("no results: %s", query)
}
return data.Gamelocalizations, nil
}

43
endpoint/game_modes.go Normal file
View File

@@ -0,0 +1,43 @@
package endpoint
import (
"context"
"fmt"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
type GameModes struct {
BaseEndpoint[pb.GameMode]
}
func NewGameModes(request RequestFunc) *GameModes {
a := &GameModes{
BaseEndpoint: BaseEndpoint[pb.GameMode]{
endpointName: EPGameModes,
request: request,
},
}
a.queryFunc = a.Query
return a
}
func (a *GameModes) Query(ctx context.Context, query string) ([]*pb.GameMode, error) {
resp, err := a.request(ctx, "POST", fmt.Sprintf("https://api.igdb.com/v4/%s.pb", a.endpointName), query)
if err != nil {
return nil, fmt.Errorf("failed to request: %w", err)
}
data := pb.GameModeResult{}
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
return nil, fmt.Errorf("failed to unmarshal: %w", err)
}
if len(data.Gamemodes) == 0 {
return nil, fmt.Errorf("no results: %s", query)
}
return data.Gamemodes, nil
}

View File

@@ -0,0 +1,43 @@
package endpoint
import (
"context"
"fmt"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
type GameReleaseFormats struct {
BaseEndpoint[pb.GameReleaseFormat]
}
func NewGameReleaseFormats(request RequestFunc) *GameReleaseFormats {
a := &GameReleaseFormats{
BaseEndpoint: BaseEndpoint[pb.GameReleaseFormat]{
endpointName: EPGameReleaseFormats,
request: request,
},
}
a.queryFunc = a.Query
return a
}
func (a *GameReleaseFormats) Query(ctx context.Context, query string) ([]*pb.GameReleaseFormat, error) {
resp, err := a.request(ctx, "POST", fmt.Sprintf("https://api.igdb.com/v4/%s.pb", a.endpointName), query)
if err != nil {
return nil, fmt.Errorf("failed to request: %w", err)
}
data := pb.GameReleaseFormatResult{}
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
return nil, fmt.Errorf("failed to unmarshal: %w", err)
}
if len(data.Gamereleaseformats) == 0 {
return nil, fmt.Errorf("no results: %s", query)
}
return data.Gamereleaseformats, nil
}

43
endpoint/game_statuses.go Normal file
View File

@@ -0,0 +1,43 @@
package endpoint
import (
"context"
"fmt"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
type GameStatuses struct {
BaseEndpoint[pb.GameStatus]
}
func NewGameStatuses(request RequestFunc) *GameStatuses {
a := &GameStatuses{
BaseEndpoint: BaseEndpoint[pb.GameStatus]{
endpointName: EPGameStatuses,
request: request,
},
}
a.queryFunc = a.Query
return a
}
func (a *GameStatuses) Query(ctx context.Context, query string) ([]*pb.GameStatus, error) {
resp, err := a.request(ctx, "POST", fmt.Sprintf("https://api.igdb.com/v4/%s.pb", a.endpointName), query)
if err != nil {
return nil, fmt.Errorf("failed to request: %w", err)
}
data := pb.GameStatusResult{}
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
return nil, fmt.Errorf("failed to unmarshal: %w", err)
}
if len(data.Gamestatuses) == 0 {
return nil, fmt.Errorf("no results: %s", query)
}
return data.Gamestatuses, nil
}

View File

@@ -0,0 +1,43 @@
package endpoint
import (
"context"
"fmt"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
type GameTimeToBeats struct {
BaseEndpoint[pb.GameTimeToBeat]
}
func NewGameTimeToBeats(request RequestFunc) *GameTimeToBeats {
a := &GameTimeToBeats{
BaseEndpoint: BaseEndpoint[pb.GameTimeToBeat]{
endpointName: EPGameTimeToBeats,
request: request,
},
}
a.queryFunc = a.Query
return a
}
func (a *GameTimeToBeats) Query(ctx context.Context, query string) ([]*pb.GameTimeToBeat, error) {
resp, err := a.request(ctx, "POST", fmt.Sprintf("https://api.igdb.com/v4/%s.pb", a.endpointName), query)
if err != nil {
return nil, fmt.Errorf("failed to request: %w", err)
}
data := pb.GameTimeToBeatResult{}
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
return nil, fmt.Errorf("failed to unmarshal: %w", err)
}
if len(data.Gametimetobeats) == 0 {
return nil, fmt.Errorf("no results: %s", query)
}
return data.Gametimetobeats, nil
}

43
endpoint/game_types.go Normal file
View File

@@ -0,0 +1,43 @@
package endpoint
import (
"context"
"fmt"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
type GameTypes struct {
BaseEndpoint[pb.GameType]
}
func NewGameTypes(request RequestFunc) *GameTypes {
a := &GameTypes{
BaseEndpoint: BaseEndpoint[pb.GameType]{
endpointName: EPGameTypes,
request: request,
},
}
a.queryFunc = a.Query
return a
}
func (a *GameTypes) Query(ctx context.Context, query string) ([]*pb.GameType, error) {
resp, err := a.request(ctx, "POST", fmt.Sprintf("https://api.igdb.com/v4/%s.pb", a.endpointName), query)
if err != nil {
return nil, fmt.Errorf("failed to request: %w", err)
}
data := pb.GameTypeResult{}
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
return nil, fmt.Errorf("failed to unmarshal: %w", err)
}
if len(data.Gametypes) == 0 {
return nil, fmt.Errorf("no results: %s", query)
}
return data.Gametypes, nil
}

View File

@@ -0,0 +1,43 @@
package endpoint
import (
"context"
"fmt"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
type GameVersionFeatureValues struct {
BaseEndpoint[pb.GameVersionFeatureValue]
}
func NewGameVersionFeatureValues(request RequestFunc) *GameVersionFeatureValues {
a := &GameVersionFeatureValues{
BaseEndpoint: BaseEndpoint[pb.GameVersionFeatureValue]{
endpointName: EPGameVersionFeatureValues,
request: request,
},
}
a.queryFunc = a.Query
return a
}
func (a *GameVersionFeatureValues) Query(ctx context.Context, query string) ([]*pb.GameVersionFeatureValue, error) {
resp, err := a.request(ctx, "POST", fmt.Sprintf("https://api.igdb.com/v4/%s.pb", a.endpointName), query)
if err != nil {
return nil, fmt.Errorf("failed to request: %w", err)
}
data := pb.GameVersionFeatureValueResult{}
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
return nil, fmt.Errorf("failed to unmarshal: %w", err)
}
if len(data.Gameversionfeaturevalues) == 0 {
return nil, fmt.Errorf("no results: %s", query)
}
return data.Gameversionfeaturevalues, nil
}

View File

@@ -0,0 +1,43 @@
package endpoint
import (
"context"
"fmt"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
type GameVersionFeatures struct {
BaseEndpoint[pb.GameVersionFeature]
}
func NewGameVersionFeatures(request RequestFunc) *GameVersionFeatures {
a := &GameVersionFeatures{
BaseEndpoint: BaseEndpoint[pb.GameVersionFeature]{
endpointName: EPGameVersionFeatures,
request: request,
},
}
a.queryFunc = a.Query
return a
}
func (a *GameVersionFeatures) Query(ctx context.Context, query string) ([]*pb.GameVersionFeature, error) {
resp, err := a.request(ctx, "POST", fmt.Sprintf("https://api.igdb.com/v4/%s.pb", a.endpointName), query)
if err != nil {
return nil, fmt.Errorf("failed to request: %w", err)
}
data := pb.GameVersionFeatureResult{}
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
return nil, fmt.Errorf("failed to unmarshal: %w", err)
}
if len(data.Gameversionfeatures) == 0 {
return nil, fmt.Errorf("no results: %s", query)
}
return data.Gameversionfeatures, nil
}

43
endpoint/game_versions.go Normal file
View File

@@ -0,0 +1,43 @@
package endpoint
import (
"context"
"fmt"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
type GameVersions struct {
BaseEndpoint[pb.GameVersion]
}
func NewGameVersions(request RequestFunc) *GameVersions {
a := &GameVersions{
BaseEndpoint: BaseEndpoint[pb.GameVersion]{
endpointName: EPGameVersions,
request: request,
},
}
a.queryFunc = a.Query
return a
}
func (a *GameVersions) Query(ctx context.Context, query string) ([]*pb.GameVersion, error) {
resp, err := a.request(ctx, "POST", fmt.Sprintf("https://api.igdb.com/v4/%s.pb", a.endpointName), query)
if err != nil {
return nil, fmt.Errorf("failed to request: %w", err)
}
data := pb.GameVersionResult{}
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
return nil, fmt.Errorf("failed to unmarshal: %w", err)
}
if len(data.Gameversions) == 0 {
return nil, fmt.Errorf("no results: %s", query)
}
return data.Gameversions, nil
}

43
endpoint/game_videos.go Normal file
View File

@@ -0,0 +1,43 @@
package endpoint
import (
"context"
"fmt"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
type GameVideos struct {
BaseEndpoint[pb.GameVideo]
}
func NewGameVideos(request RequestFunc) *GameVideos {
a := &GameVideos{
BaseEndpoint: BaseEndpoint[pb.GameVideo]{
endpointName: EPGameVideos,
request: request,
},
}
a.queryFunc = a.Query
return a
}
func (a *GameVideos) Query(ctx context.Context, query string) ([]*pb.GameVideo, error) {
resp, err := a.request(ctx, "POST", fmt.Sprintf("https://api.igdb.com/v4/%s.pb", a.endpointName), query)
if err != nil {
return nil, fmt.Errorf("failed to request: %w", err)
}
data := pb.GameVideoResult{}
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
return nil, fmt.Errorf("failed to unmarshal: %w", err)
}
if len(data.Gamevideos) == 0 {
return nil, fmt.Errorf("no results: %s", query)
}
return data.Gamevideos, nil
}

43
endpoint/games.go Normal file
View File

@@ -0,0 +1,43 @@
package endpoint
import (
"context"
"fmt"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
type Games struct {
BaseEndpoint[pb.Game]
}
func NewGames(request RequestFunc) *Games {
a := &Games{
BaseEndpoint: BaseEndpoint[pb.Game]{
endpointName: EPGames,
request: request,
},
}
a.queryFunc = a.Query
return a
}
func (a *Games) Query(ctx context.Context, query string) ([]*pb.Game, error) {
resp, err := a.request(ctx, "POST", fmt.Sprintf("https://api.igdb.com/v4/%s.pb", a.endpointName), query)
if err != nil {
return nil, fmt.Errorf("failed to request: %w", err)
}
data := pb.GameResult{}
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
return nil, fmt.Errorf("failed to unmarshal: %w", err)
}
if len(data.Games) == 0 {
return nil, fmt.Errorf("no results: %s", query)
}
return data.Games, nil
}

43
endpoint/genres.go Normal file
View File

@@ -0,0 +1,43 @@
package endpoint
import (
"context"
"fmt"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
type Genres struct {
BaseEndpoint[pb.Genre]
}
func NewGenres(request RequestFunc) *Genres {
a := &Genres{
BaseEndpoint: BaseEndpoint[pb.Genre]{
endpointName: EPGenres,
request: request,
},
}
a.queryFunc = a.Query
return a
}
func (a *Genres) Query(ctx context.Context, query string) ([]*pb.Genre, error) {
resp, err := a.request(ctx, "POST", fmt.Sprintf("https://api.igdb.com/v4/%s.pb", a.endpointName), query)
if err != nil {
return nil, fmt.Errorf("failed to request: %w", err)
}
data := pb.GenreResult{}
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
return nil, fmt.Errorf("failed to unmarshal: %w", err)
}
if len(data.Genres) == 0 {
return nil, fmt.Errorf("no results: %s", query)
}
return data.Genres, nil
}

View File

@@ -0,0 +1,43 @@
package endpoint
import (
"context"
"fmt"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
type InvolvedCompanies struct {
BaseEndpoint[pb.InvolvedCompany]
}
func NewInvolvedCompanies(request RequestFunc) *InvolvedCompanies {
a := &InvolvedCompanies{
BaseEndpoint: BaseEndpoint[pb.InvolvedCompany]{
endpointName: EPInvolvedCompanies,
request: request,
},
}
a.queryFunc = a.Query
return a
}
func (a *InvolvedCompanies) Query(ctx context.Context, query string) ([]*pb.InvolvedCompany, error) {
resp, err := a.request(ctx, "POST", fmt.Sprintf("https://api.igdb.com/v4/%s.pb", a.endpointName), query)
if err != nil {
return nil, fmt.Errorf("failed to request: %w", err)
}
data := pb.InvolvedCompanyResult{}
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
return nil, fmt.Errorf("failed to unmarshal: %w", err)
}
if len(data.Involvedcompanies) == 0 {
return nil, fmt.Errorf("no results: %s", query)
}
return data.Involvedcompanies, nil
}

43
endpoint/keywords.go Normal file
View File

@@ -0,0 +1,43 @@
package endpoint
import (
"context"
"fmt"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
type Keywords struct {
BaseEndpoint[pb.Keyword]
}
func NewKeywords(request RequestFunc) *Keywords {
a := &Keywords{
BaseEndpoint: BaseEndpoint[pb.Keyword]{
endpointName: EPKeywords,
request: request,
},
}
a.queryFunc = a.Query
return a
}
func (a *Keywords) Query(ctx context.Context, query string) ([]*pb.Keyword, error) {
resp, err := a.request(ctx, "POST", fmt.Sprintf("https://api.igdb.com/v4/%s.pb", a.endpointName), query)
if err != nil {
return nil, fmt.Errorf("failed to request: %w", err)
}
data := pb.KeywordResult{}
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
return nil, fmt.Errorf("failed to unmarshal: %w", err)
}
if len(data.Keywords) == 0 {
return nil, fmt.Errorf("no results: %s", query)
}
return data.Keywords, nil
}

View File

@@ -0,0 +1,43 @@
package endpoint
import (
"context"
"fmt"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
type LanguageSupportTypes struct {
BaseEndpoint[pb.LanguageSupportType]
}
func NewLanguageSupportTypes(request RequestFunc) *LanguageSupportTypes {
a := &LanguageSupportTypes{
BaseEndpoint[pb.LanguageSupportType]{
endpointName: EPLanguageSupportTypes,
request: request,
},
}
a.queryFunc = a.Query
return a
}
func (a *LanguageSupportTypes) Query(ctx context.Context, query string) ([]*pb.LanguageSupportType, error) {
resp, err := a.request(ctx, "POST", fmt.Sprintf("https://api.igdb.com/v4/%s.pb", a.endpointName), query)
if err != nil {
return nil, fmt.Errorf("failed to request: %w", err)
}
data := pb.LanguageSupportTypeResult{}
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
return nil, fmt.Errorf("failed to unmarshal: %w", err)
}
if len(data.Languagesupporttypes) == 0 {
return nil, fmt.Errorf("no results: %s", query)
}
return data.Languagesupporttypes, nil
}

View File

@@ -0,0 +1,43 @@
package endpoint
import (
"context"
"fmt"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
type LanguageSupports struct {
BaseEndpoint[pb.LanguageSupport]
}
func NewLanguageSupports(request RequestFunc) *LanguageSupports {
a := &LanguageSupports{
BaseEndpoint: BaseEndpoint[pb.LanguageSupport]{
endpointName: EPLanguageSupports,
request: request,
},
}
a.queryFunc = a.Query
return a
}
func (a *LanguageSupports) Query(ctx context.Context, query string) ([]*pb.LanguageSupport, error) {
resp, err := a.request(ctx, "POST", fmt.Sprintf("https://api.igdb.com/v4/%s.pb", a.endpointName), query)
if err != nil {
return nil, fmt.Errorf("failed to request: %w", err)
}
data := pb.LanguageSupportResult{}
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
return nil, fmt.Errorf("failed to unmarshal: %w", err)
}
if len(data.Languagesupports) == 0 {
return nil, fmt.Errorf("no results: %s", query)
}
return data.Languagesupports, nil
}

43
endpoint/languages.go Normal file
View File

@@ -0,0 +1,43 @@
package endpoint
import (
"context"
"fmt"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
type Languages struct {
BaseEndpoint[pb.Language]
}
func NewLanguages(request RequestFunc) *Languages {
a := &Languages{
BaseEndpoint: BaseEndpoint[pb.Language]{
endpointName: EPLanguages,
request: request,
},
}
a.queryFunc = a.Query
return a
}
func (a *Languages) Query(ctx context.Context, query string) ([]*pb.Language, error) {
resp, err := a.request(ctx, "POST", fmt.Sprintf("https://api.igdb.com/v4/%s.pb", a.endpointName), query)
if err != nil {
return nil, fmt.Errorf("failed to request: %w", err)
}
data := pb.LanguageResult{}
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
return nil, fmt.Errorf("failed to unmarshal: %w", err)
}
if len(data.Languages) == 0 {
return nil, fmt.Errorf("no results: %s", query)
}
return data.Languages, nil
}

View File

@@ -0,0 +1,43 @@
package endpoint
import (
"context"
"fmt"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
type MultiplayerModes struct {
BaseEndpoint[pb.MultiplayerMode]
}
func NewMultiplayerModes(request RequestFunc) *MultiplayerModes {
a := &MultiplayerModes{
BaseEndpoint: BaseEndpoint[pb.MultiplayerMode]{
endpointName: EPMultiplayerModes,
request: request,
},
}
a.queryFunc = a.Query
return a
}
func (a *MultiplayerModes) Query(ctx context.Context, query string) ([]*pb.MultiplayerMode, error) {
resp, err := a.request(ctx, "POST", fmt.Sprintf("https://api.igdb.com/v4/%s.pb", a.endpointName), query)
if err != nil {
return nil, fmt.Errorf("failed to request: %w", err)
}
data := pb.MultiplayerModeResult{}
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
return nil, fmt.Errorf("failed to unmarshal: %w", err)
}
if len(data.Multiplayermodes) == 0 {
return nil, fmt.Errorf("no results: %s", query)
}
return data.Multiplayermodes, nil
}

43
endpoint/network_types.go Normal file
View File

@@ -0,0 +1,43 @@
package endpoint
import (
"context"
"fmt"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
type NetworkTypes struct {
BaseEndpoint[pb.NetworkType]
}
func NewNetworkTypes(request RequestFunc) *NetworkTypes {
a := &NetworkTypes{
BaseEndpoint: BaseEndpoint[pb.NetworkType]{
endpointName: EPNetworkTypes,
request: request,
},
}
a.queryFunc = a.Query
return a
}
func (a *NetworkTypes) Query(ctx context.Context, query string) ([]*pb.NetworkType, error) {
resp, err := a.request(ctx, "POST", fmt.Sprintf("https://api.igdb.com/v4/%s.pb", a.endpointName), query)
if err != nil {
return nil, fmt.Errorf("failed to request: %w", err)
}
data := pb.NetworkTypeResult{}
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
return nil, fmt.Errorf("failed to unmarshal: %w", err)
}
if len(data.Networktypes) == 0 {
return nil, fmt.Errorf("no results: %s", query)
}
return data.Networktypes, nil
}

View File

@@ -0,0 +1,43 @@
package endpoint
import (
"context"
"fmt"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
type PlatformFamilies struct {
BaseEndpoint[pb.PlatformFamily]
}
func NewPlatformFamilies(request RequestFunc) *PlatformFamilies {
a := &PlatformFamilies{
BaseEndpoint: BaseEndpoint[pb.PlatformFamily]{
endpointName: EPPlatformFamilies,
request: request,
},
}
a.queryFunc = a.Query
return a
}
func (a *PlatformFamilies) Query(ctx context.Context, query string) ([]*pb.PlatformFamily, error) {
resp, err := a.request(ctx, "POST", fmt.Sprintf("https://api.igdb.com/v4/%s.pb", a.endpointName), query)
if err != nil {
return nil, fmt.Errorf("failed to request: %w", err)
}
data := pb.PlatformFamilyResult{}
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
return nil, fmt.Errorf("failed to unmarshal: %w", err)
}
if len(data.Platformfamilies) == 0 {
return nil, fmt.Errorf("no results: %s", query)
}
return data.Platformfamilies, nil
}

View File

@@ -0,0 +1,43 @@
package endpoint
import (
"context"
"fmt"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
type PlatformLogos struct {
BaseEndpoint[pb.PlatformLogo]
}
func NewPlatformLogos(request RequestFunc) *PlatformLogos {
a := &PlatformLogos{
BaseEndpoint: BaseEndpoint[pb.PlatformLogo]{
endpointName: EPPlatformLogos,
request: request,
},
}
a.queryFunc = a.Query
return a
}
func (a *PlatformLogos) Query(ctx context.Context, query string) ([]*pb.PlatformLogo, error) {
resp, err := a.request(ctx, "POST", fmt.Sprintf("https://api.igdb.com/v4/%s.pb", a.endpointName), query)
if err != nil {
return nil, fmt.Errorf("failed to request: %w", err)
}
data := pb.PlatformLogoResult{}
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
return nil, fmt.Errorf("failed to unmarshal: %w", err)
}
if len(data.Platformlogos) == 0 {
return nil, fmt.Errorf("no results: %s", query)
}
return data.Platformlogos, nil
}

View File

@@ -0,0 +1,43 @@
package endpoint
import (
"context"
"fmt"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
type PlatformTypes struct {
BaseEndpoint[pb.PlatformType]
}
func NewPlatformTypes(request RequestFunc) *PlatformTypes {
a := &PlatformTypes{
BaseEndpoint: BaseEndpoint[pb.PlatformType]{
endpointName: EPPlatformTypes,
request: request,
},
}
a.queryFunc = a.Query
return a
}
func (a *PlatformTypes) Query(ctx context.Context, query string) ([]*pb.PlatformType, error) {
resp, err := a.request(ctx, "POST", fmt.Sprintf("https://api.igdb.com/v4/%s.pb", a.endpointName), query)
if err != nil {
return nil, fmt.Errorf("failed to request: %w", err)
}
data := pb.PlatformTypeResult{}
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
return nil, fmt.Errorf("failed to unmarshal: %w", err)
}
if len(data.Platformtypes) == 0 {
return nil, fmt.Errorf("no results: %s", query)
}
return data.Platformtypes, nil
}

View File

@@ -0,0 +1,43 @@
package endpoint
import (
"context"
"fmt"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
type PlatformVersionCompanies struct {
BaseEndpoint[pb.PlatformVersionCompany]
}
func NewPlatformVersionCompanies(request RequestFunc) *PlatformVersionCompanies {
a := &PlatformVersionCompanies{
BaseEndpoint: BaseEndpoint[pb.PlatformVersionCompany]{
endpointName: EPPlatformVersionCompanies,
request: request,
},
}
a.queryFunc = a.Query
return a
}
func (a *PlatformVersionCompanies) Query(ctx context.Context, query string) ([]*pb.PlatformVersionCompany, error) {
resp, err := a.request(ctx, "POST", fmt.Sprintf("https://api.igdb.com/v4/%s.pb", a.endpointName), query)
if err != nil {
return nil, fmt.Errorf("failed to request: %w", err)
}
data := pb.PlatformVersionCompanyResult{}
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
return nil, fmt.Errorf("failed to unmarshal: %w", err)
}
if len(data.Platformversioncompanies) == 0 {
return nil, fmt.Errorf("no results: %s", query)
}
return data.Platformversioncompanies, nil
}

View File

@@ -0,0 +1,43 @@
package endpoint
import (
"context"
"fmt"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
type PlatformVersionReleaseDates struct {
BaseEndpoint[pb.PlatformVersionReleaseDate]
}
func NewPlatformVersionReleaseDates(request RequestFunc) *PlatformVersionReleaseDates {
a := &PlatformVersionReleaseDates{
BaseEndpoint: BaseEndpoint[pb.PlatformVersionReleaseDate]{
endpointName: EPPlatformVersionReleaseDates,
request: request,
},
}
a.queryFunc = a.Query
return a
}
func (a *PlatformVersionReleaseDates) Query(ctx context.Context, query string) ([]*pb.PlatformVersionReleaseDate, error) {
resp, err := a.request(ctx, "POST", fmt.Sprintf("https://api.igdb.com/v4/%s.pb", a.endpointName), query)
if err != nil {
return nil, fmt.Errorf("failed to request: %w", err)
}
data := pb.PlatformVersionReleaseDateResult{}
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
return nil, fmt.Errorf("failed to unmarshal: %w", err)
}
if len(data.Platformversionreleasedates) == 0 {
return nil, fmt.Errorf("no results: %s", query)
}
return data.Platformversionreleasedates, nil
}

View File

@@ -0,0 +1,43 @@
package endpoint
import (
"context"
"fmt"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
type PlatformVersions struct {
BaseEndpoint[pb.PlatformVersion]
}
func NewPlatformVersions(request RequestFunc) *PlatformVersions {
a := &PlatformVersions{
BaseEndpoint: BaseEndpoint[pb.PlatformVersion]{
endpointName: EPPlatformVersions,
request: request,
},
}
a.queryFunc = a.Query
return a
}
func (a *PlatformVersions) Query(ctx context.Context, query string) ([]*pb.PlatformVersion, error) {
resp, err := a.request(ctx, "POST", fmt.Sprintf("https://api.igdb.com/v4/%s.pb", a.endpointName), query)
if err != nil {
return nil, fmt.Errorf("failed to request: %w", err)
}
data := pb.PlatformVersionResult{}
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
return nil, fmt.Errorf("failed to unmarshal: %w", err)
}
if len(data.Platformversions) == 0 {
return nil, fmt.Errorf("no results: %s", query)
}
return data.Platformversions, nil
}

View File

@@ -0,0 +1,43 @@
package endpoint
import (
"context"
"fmt"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
type PlatformWebsites struct {
BaseEndpoint[pb.PlatformWebsite]
}
func NewPlatformWebsites(request RequestFunc) *PlatformWebsites {
a := &PlatformWebsites{
BaseEndpoint: BaseEndpoint[pb.PlatformWebsite]{
endpointName: EPPlatformWebsites,
request: request,
},
}
a.queryFunc = a.Query
return a
}
func (a *PlatformWebsites) Query(ctx context.Context, query string) ([]*pb.PlatformWebsite, error) {
resp, err := a.request(ctx, "POST", fmt.Sprintf("https://api.igdb.com/v4/%s.pb", a.endpointName), query)
if err != nil {
return nil, fmt.Errorf("failed to request: %w", err)
}
data := pb.PlatformWebsiteResult{}
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
return nil, fmt.Errorf("failed to unmarshal: %w", err)
}
if len(data.Platformwebsites) == 0 {
return nil, fmt.Errorf("no results: %s", query)
}
return data.Platformwebsites, nil
}

42
endpoint/platforms.go Normal file
View File

@@ -0,0 +1,42 @@
package endpoint
import (
"context"
"fmt"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
type Platforms struct {
BaseEndpoint[pb.Platform]
}
func NewPlatforms(request RequestFunc) *Platforms {
a := &Platforms{
BaseEndpoint[pb.Platform]{
endpointName: EPPlatforms,
request: request,
},
}
a.queryFunc = a.Query
return a
}
func (a *Platforms) Query(ctx context.Context, query string) ([]*pb.Platform, error) {
resp, err := a.request(ctx, "POST", fmt.Sprintf("https://api.igdb.com/v4/%s.pb", a.endpointName), query)
if err != nil {
return nil, fmt.Errorf("failed to request: %w", err)
}
data := pb.PlatformResult{}
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
return nil, fmt.Errorf("failed to unmarshal: %w", err)
}
if len(data.Platforms) == 0 {
return nil, fmt.Errorf("no results: %s", query)
}
return data.Platforms, nil
}

View File

@@ -0,0 +1,43 @@
package endpoint
import (
"context"
"fmt"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
type PlayerPerspectives struct {
BaseEndpoint[pb.PlayerPerspective]
}
func NewPlayerPerspectives(request RequestFunc) *PlayerPerspectives {
a := &PlayerPerspectives{
BaseEndpoint: BaseEndpoint[pb.PlayerPerspective]{
endpointName: EPPlayerPerspectives,
request: request,
},
}
a.queryFunc = a.Query
return a
}
func (a *PlayerPerspectives) Query(ctx context.Context, query string) ([]*pb.PlayerPerspective, error) {
resp, err := a.request(ctx, "POST", fmt.Sprintf("https://api.igdb.com/v4/%s.pb", a.endpointName), query)
if err != nil {
return nil, fmt.Errorf("failed to request: %w", err)
}
data := pb.PlayerPerspectiveResult{}
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
return nil, fmt.Errorf("failed to unmarshal: %w", err)
}
if len(data.Playerperspectives) == 0 {
return nil, fmt.Errorf("no results: %s", query)
}
return data.Playerperspectives, nil
}

View File

@@ -0,0 +1,43 @@
package endpoint
import (
"context"
"fmt"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
type PopularityPrimitives struct {
BaseEndpoint[pb.PopularityPrimitive]
}
func NewPopularityPrimitives(request RequestFunc) *PopularityPrimitives {
a := &PopularityPrimitives{
BaseEndpoint[pb.PopularityPrimitive]{
endpointName: EPPopularityPrimitives,
request: request,
},
}
a.queryFunc = a.Query
return a
}
func (a *PopularityPrimitives) Query(ctx context.Context, query string) ([]*pb.PopularityPrimitive, error) {
resp, err := a.request(ctx, "POST", fmt.Sprintf("https://api.igdb.com/v4/%s.pb", a.endpointName), query)
if err != nil {
return nil, fmt.Errorf("failed to request: %w", err)
}
data := pb.PopularityPrimitiveResult{}
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
return nil, fmt.Errorf("failed to unmarshal: %w", err)
}
if len(data.Popularityprimitives) == 0 {
return nil, fmt.Errorf("no results: %s", query)
}
return data.Popularityprimitives, nil
}

View File

@@ -0,0 +1,43 @@
package endpoint
import (
"context"
"fmt"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
type PopularityTypes struct {
BaseEndpoint[pb.PopularityType]
}
func NewPopularityTypes(request RequestFunc) *PopularityTypes {
a := &PopularityTypes{
BaseEndpoint: BaseEndpoint[pb.PopularityType]{
endpointName: EPPopularityTypes,
request: request,
},
}
a.queryFunc = a.Query
return a
}
func (a *PopularityTypes) Query(ctx context.Context, query string) ([]*pb.PopularityType, error) {
resp, err := a.request(ctx, "POST", fmt.Sprintf("https://api.igdb.com/v4/%s.pb", a.endpointName), query)
if err != nil {
return nil, fmt.Errorf("failed to request: %w", err)
}
data := pb.PopularityTypeResult{}
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
return nil, fmt.Errorf("failed to unmarshal: %w", err)
}
if len(data.Popularitytypes) == 0 {
return nil, fmt.Errorf("no results: %s", query)
}
return data.Popularitytypes, nil
}

43
endpoint/regions.go Normal file
View File

@@ -0,0 +1,43 @@
package endpoint
import (
"context"
"fmt"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
type Regions struct {
BaseEndpoint[pb.Region]
}
func NewRegions(request RequestFunc) *Regions {
a := &Regions{
BaseEndpoint: BaseEndpoint[pb.Region]{
endpointName: EPRegions,
request: request,
},
}
a.queryFunc = a.Query
return a
}
func (a *Regions) Query(ctx context.Context, query string) ([]*pb.Region, error) {
resp, err := a.request(ctx, "POST", fmt.Sprintf("https://api.igdb.com/v4/%s.pb", a.endpointName), query)
if err != nil {
return nil, fmt.Errorf("failed to request: %w", err)
}
data := pb.RegionResult{}
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
return nil, fmt.Errorf("failed to unmarshal: %w", err)
}
if len(data.Regions) == 0 {
return nil, fmt.Errorf("no results: %s", query)
}
return data.Regions, nil
}

View File

@@ -0,0 +1,43 @@
package endpoint
import (
"context"
"fmt"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
type ReleaseDateRegions struct {
BaseEndpoint[pb.ReleaseDateRegion]
}
func NewReleaseDateRegions(request RequestFunc) *ReleaseDateRegions {
a := &ReleaseDateRegions{
BaseEndpoint: BaseEndpoint[pb.ReleaseDateRegion]{
endpointName: EPReleaseDateRegions,
request: request,
},
}
a.queryFunc = a.Query
return a
}
func (a *ReleaseDateRegions) Query(ctx context.Context, query string) ([]*pb.ReleaseDateRegion, error) {
resp, err := a.request(ctx, "POST", fmt.Sprintf("https://api.igdb.com/v4/%s.pb", a.endpointName), query)
if err != nil {
return nil, fmt.Errorf("failed to request: %w", err)
}
data := pb.ReleaseDateRegionResult{}
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
return nil, fmt.Errorf("failed to unmarshal: %w", err)
}
if len(data.Releasedateregions) == 0 {
return nil, fmt.Errorf("no results: %s", query)
}
return data.Releasedateregions, nil
}

View File

@@ -0,0 +1,43 @@
package endpoint
import (
"context"
"fmt"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
type ReleaseDateStatuses struct {
BaseEndpoint[pb.ReleaseDateStatus]
}
func NewReleaseDateStatuses(request RequestFunc) *ReleaseDateStatuses {
a := &ReleaseDateStatuses{
BaseEndpoint: BaseEndpoint[pb.ReleaseDateStatus]{
endpointName: EPReleaseDateStatuses,
request: request,
},
}
a.queryFunc = a.Query
return a
}
func (a *ReleaseDateStatuses) Query(ctx context.Context, query string) ([]*pb.ReleaseDateStatus, error) {
resp, err := a.request(ctx, "POST", fmt.Sprintf("https://api.igdb.com/v4/%s.pb", a.endpointName), query)
if err != nil {
return nil, fmt.Errorf("failed to request: %w", err)
}
data := pb.ReleaseDateStatusResult{}
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
return nil, fmt.Errorf("failed to unmarshal: %w", err)
}
if len(data.Releasedatestatuses) == 0 {
return nil, fmt.Errorf("no results: %s", query)
}
return data.Releasedatestatuses, nil
}

43
endpoint/release_dates.go Normal file
View File

@@ -0,0 +1,43 @@
package endpoint
import (
"context"
"fmt"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
type ReleaseDates struct {
BaseEndpoint[pb.ReleaseDate]
}
func NewReleaseDates(request RequestFunc) *ReleaseDates {
a := &ReleaseDates{
BaseEndpoint: BaseEndpoint[pb.ReleaseDate]{
endpointName: EPReleaseDates,
request: request,
},
}
a.queryFunc = a.Query
return a
}
func (a *ReleaseDates) Query(ctx context.Context, query string) ([]*pb.ReleaseDate, error) {
resp, err := a.request(ctx, "POST", fmt.Sprintf("https://api.igdb.com/v4/%s.pb", a.endpointName), query)
if err != nil {
return nil, fmt.Errorf("failed to request: %w", err)
}
data := pb.ReleaseDateResult{}
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
return nil, fmt.Errorf("failed to unmarshal: %w", err)
}
if len(data.Releasedates) == 0 {
return nil, fmt.Errorf("no results: %s", query)
}
return data.Releasedates, nil
}

43
endpoint/screenshots.go Normal file
View File

@@ -0,0 +1,43 @@
package endpoint
import (
"context"
"fmt"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
type Screenshots struct {
BaseEndpoint[pb.Screenshot]
}
func NewScreenshots(request RequestFunc) *Screenshots {
a := &Screenshots{
BaseEndpoint: BaseEndpoint[pb.Screenshot]{
endpointName: EPScreenshots,
request: request,
},
}
a.queryFunc = a.Query
return a
}
func (a *Screenshots) Query(ctx context.Context, query string) ([]*pb.Screenshot, error) {
resp, err := a.request(ctx, "POST", fmt.Sprintf("https://api.igdb.com/v4/%s.pb", a.endpointName), query)
if err != nil {
return nil, fmt.Errorf("failed to request: %w", err)
}
data := pb.ScreenshotResult{}
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
return nil, fmt.Errorf("failed to unmarshal: %w", err)
}
if len(data.Screenshots) == 0 {
return nil, fmt.Errorf("no results: %s", query)
}
return data.Screenshots, nil
}

View File

@@ -1,52 +1,72 @@
package igdb
package endpoint
import (
"context"
"encoding/json"
"fmt"
"github/bestnite/go-igdb/constant"
"io"
"net/http"
"net/url"
"strings"
"time"
pb "github/bestnite/go-igdb/proto"
pb "github.com/bestnite/go-igdb/proto"
"github.com/PuerkitoBio/goquery"
"github.com/bestnite/go-flaresolverr"
"google.golang.org/protobuf/proto"
)
func (g *igdb) SearchGame(query string) ([]*pb.Game, error) {
resp, err := g.Request(constant.IGDBGameURL, query)
if err != nil {
return nil, fmt.Errorf("failed to search: %s: %w", query, err)
}
data := pb.GameResult{}
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
return nil, fmt.Errorf("failed to parse IGDB search response: %w", err)
}
if len(data.Games) != 0 && data.Games[0].Name == "" {
return g.WebSearchGame(query)
}
return data.Games, nil
}
var webSearchCFCookies struct {
cookies []*http.Cookie
expires time.Time
}
func (g *igdb) WebSearchGame(name string) ([]*pb.Game, error) {
type Search struct {
endpointName Name
request RequestFunc
flaresolverr *flaresolverr.Flaresolverr
}
func NewSearch(request RequestFunc) *Search {
return &Search{
endpointName: EPSearch,
request: request,
}
}
func (a *Search) Search(ctx context.Context, query string) ([]*pb.Search, error) {
resp, err := a.request(ctx, "POST", fmt.Sprintf("https://api.igdb.com/v4/%s.pb", a.endpointName), query)
if err != nil {
return nil, fmt.Errorf("failed to request: %w", err)
}
data := pb.SearchResult{}
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
return nil, fmt.Errorf("failed to unmarshal: %w", err)
}
if len(data.Searches) == 0 {
return nil, fmt.Errorf("no results: %s", query)
}
return data.Searches, nil
}
func (a *Search) getFlaresolverr() (*flaresolverr.Flaresolverr, error) {
if a.flaresolverr == nil {
return nil, fmt.Errorf("flaresolverr is not initialized")
}
return a.flaresolverr, nil
}
func (a *Search) WebSearchGameIDs(name string) ([]uint64, error) {
params := url.Values{}
params.Add("q", name)
params.Add("utf8", "✓")
Url := fmt.Sprintf("%s?%s", constant.IGDBWebSearchURL, params.Encode())
Url := fmt.Sprintf("%s?%s", "https://www.igdb.com/search", params.Encode())
f, err := g.getFlaresolverr()
f, err := a.getFlaresolverr()
if err != nil {
return nil, fmt.Errorf("failed to get flaresolverr: %w", err)
}
@@ -94,5 +114,5 @@ func (g *igdb) WebSearchGame(name string) ([]*pb.Game, error) {
ids[i] = game.Id
}
return g.GetGames(ids)
return ids, nil
}

43
endpoint/themes.go Normal file
View File

@@ -0,0 +1,43 @@
package endpoint
import (
"context"
"fmt"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
type Themes struct {
BaseEndpoint[pb.Theme]
}
func NewThemes(request RequestFunc) *Themes {
a := &Themes{
BaseEndpoint: BaseEndpoint[pb.Theme]{
endpointName: EPThemes,
request: request,
},
}
a.queryFunc = a.Query
return a
}
func (a *Themes) Query(ctx context.Context, query string) ([]*pb.Theme, error) {
resp, err := a.request(ctx, "POST", fmt.Sprintf("https://api.igdb.com/v4/%s.pb", a.endpointName), query)
if err != nil {
return nil, fmt.Errorf("failed to request: %w", err)
}
data := pb.ThemeResult{}
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
return nil, fmt.Errorf("failed to unmarshal: %w", err)
}
if len(data.Themes) == 0 {
return nil, fmt.Errorf("no results: %s", query)
}
return data.Themes, nil
}

104
endpoint/webhooks.go Normal file
View File

@@ -0,0 +1,104 @@
package endpoint
import (
"context"
"encoding/json"
"fmt"
"net/http"
"net/url"
)
type Webhooks struct {
request RequestFunc
}
func NewWebhooks(request RequestFunc) *Webhooks {
return &Webhooks{
request: request,
}
}
type WebhookMethod string
const (
WebhookMethodUpdate WebhookMethod = "update"
WebhookMethodDelete WebhookMethod = "delete"
WebhookMethodCreate WebhookMethod = "create"
)
type WebhookResponse struct {
Id uint64 `json:"id"`
Url string `json:"url"`
Category uint64 `json:"category"`
SubCategory uint64 `json:"sub_category"`
Active bool `json:"active"`
ApiKey string `json:"api_key"`
Secret string `json:"secret"`
CreatedAt string `json:"created_at"`
UpdatedAt string `json:"updated_at"`
}
func (a *Webhooks) Register(ctx context.Context, endpoint Name, secret, callbackUrl string, method WebhookMethod) (*WebhookResponse, error) {
dataBody := url.Values{}
dataBody.Set("url", callbackUrl)
dataBody.Set("secret", secret)
dataBody.Set("method", string(method))
resp, err := a.request(ctx, "POST", fmt.Sprintf("https://api.igdb.com/v4/%s/webhooks/", endpoint), dataBody.Encode())
if err != nil {
return nil, fmt.Errorf("failed to make request: %s: %w", callbackUrl, err)
}
if resp.StatusCode() == http.StatusOK {
return nil, nil
}
var data WebhookResponse
if err = json.Unmarshal(resp.Body(), &data); err != nil {
return nil, fmt.Errorf("failed to unmarshal: %w", err)
}
return &data, fmt.Errorf("failed to activate webhook: %s: %s", callbackUrl, resp.String())
}
func (a *Webhooks) Unregister(ctx context.Context, webhookId uint64) error {
resp, err := a.request(ctx, "DELETE", fmt.Sprintf("https://api.igdb.com/v4/webhooks/%v", webhookId), "")
if err != nil {
return fmt.Errorf("failed to make request: %w", err)
}
if resp.StatusCode() == http.StatusOK {
return nil
}
return fmt.Errorf("failed to unregister webhook: %s", resp.String())
}
func (a *Webhooks) List(ctx context.Context) ([]*WebhookResponse, error) {
resp, err := a.request(ctx, "GET", "https://api.igdb.com/v4/webhooks/", "")
if err != nil {
return nil, fmt.Errorf("failed to make request: %w", err)
}
var data []*WebhookResponse
if err = json.Unmarshal(resp.Body(), &data); err != nil {
return nil, fmt.Errorf("failed to unmarshal: %w", err)
}
return data, nil
}
func (a *Webhooks) Get(ctx context.Context, webhookId uint64) (*WebhookResponse, error) {
resp, err := a.request(ctx, "GET", fmt.Sprintf("https://api.igdb.com/v4/webhooks/%v", webhookId), "")
if err != nil {
return nil, fmt.Errorf("failed to make request: %w", err)
}
var data WebhookResponse
if err = json.Unmarshal(resp.Body(), &data); err != nil {
return nil, fmt.Errorf("failed to unmarshal: %w", err)
}
return &data, nil
}

43
endpoint/website_types.go Normal file
View File

@@ -0,0 +1,43 @@
package endpoint
import (
"context"
"fmt"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
type WebsiteTypes struct {
BaseEndpoint[pb.WebsiteType]
}
func NewWebsiteTypes(request RequestFunc) *WebsiteTypes {
a := &WebsiteTypes{
BaseEndpoint: BaseEndpoint[pb.WebsiteType]{
endpointName: EPWebsiteTypes,
request: request,
},
}
a.queryFunc = a.Query
return a
}
func (a *WebsiteTypes) Query(ctx context.Context, query string) ([]*pb.WebsiteType, error) {
resp, err := a.request(ctx, "POST", fmt.Sprintf("https://api.igdb.com/v4/%s.pb", a.endpointName), query)
if err != nil {
return nil, fmt.Errorf("failed to request: %w", err)
}
data := pb.WebsiteTypeResult{}
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
return nil, fmt.Errorf("failed to unmarshal: %w", err)
}
if len(data.Websitetypes) == 0 {
return nil, fmt.Errorf("no results: %s", query)
}
return data.Websitetypes, nil
}

43
endpoint/websites.go Normal file
View File

@@ -0,0 +1,43 @@
package endpoint
import (
"context"
"fmt"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
type Websites struct {
BaseEndpoint[pb.Website]
}
func NewWebsites(request RequestFunc) *Websites {
a := &Websites{
BaseEndpoint: BaseEndpoint[pb.Website]{
endpointName: EPWebsites,
request: request,
},
}
a.queryFunc = a.Query
return a
}
func (a *Websites) Query(ctx context.Context, query string) ([]*pb.Website, error) {
resp, err := a.request(ctx, "POST", fmt.Sprintf("https://api.igdb.com/v4/%s.pb", a.endpointName), query)
if err != nil {
return nil, fmt.Errorf("failed to request: %w", err)
}
data := pb.WebsiteResult{}
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
return nil, fmt.Errorf("failed to unmarshal: %w", err)
}
if len(data.Websites) == 0 {
return nil, fmt.Errorf("no results: %s", query)
}
return data.Websites, nil
}

63
game.go
View File

@@ -1,63 +0,0 @@
package igdb
import (
"fmt"
"github/bestnite/go-igdb/constant"
"strconv"
"strings"
pb "github/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
func (g *igdb) GetGame(id uint64) (*pb.Game, error) {
resp, err := g.Request(constant.IGDBGameURL, fmt.Sprintf(`where id = %v; fields *, age_ratings.*, alternative_names.*, artworks.*, collection.*, cover.*, external_games.*, external_games.platform.* , franchise.*, game_engines.*, game_engines.logo.*, game_engines.companies.* , game_modes.*, genres.*, involved_companies.*, involved_companies.company.* , keywords.*, multiplayer_modes.*, multiplayer_modes.platform.*, platforms.*, platforms.platform_logo.*, platforms.platform_family.*, platforms.versions.*, platforms.websites.* , player_perspectives.*, release_dates.*, release_dates.platform.*, release_dates.status.* , screenshots.*, themes.*, videos.*, websites.*, language_supports.*, language_supports.language.*, language_supports.language_support_type.* , game_localizations.*, game_localizations.region.* , collections.*, collections.type.*, collections.as_parent_relations.child_collection.*, collections.as_parent_relations.parent_collection.*, collections.as_parent_relations.type.*,collections.as_child_relations.child_collection.*, collections.as_child_relations.parent_collection.*, collections.as_child_relations.type.*, age_ratings.content_descriptions.*, cover.game_localization.*;`, id))
if err != nil {
return nil, fmt.Errorf("failed to fetch game detail for ID %d: %w", id, err)
}
res := pb.GameResult{}
if err = proto.Unmarshal(resp.Body(), &res); err != nil {
return nil, fmt.Errorf("failed to unmarshal game detail response: %w", err)
}
if len(res.Games) == 0 {
return nil, fmt.Errorf("failed to fetch game detail for ID %d", id)
}
if res.Games[0].Name == "" {
return g.GetGame(id)
}
return res.Games[0], nil
}
func (g *igdb) GetGames(ids []uint64) ([]*pb.Game, error) {
idStrSlice := make([]string, len(ids))
for i, id := range ids {
idStrSlice[i] = strconv.FormatUint(id, 10)
}
idStr := strings.Join(idStrSlice, ",")
resp, err := g.Request(constant.IGDBGameURL, fmt.Sprintf(`where id = (%s); fields *, age_ratings.*, alternative_names.*, artworks.*, collection.*, cover.*, external_games.*, external_games.platform.* , franchise.*, game_engines.*, game_engines.logo.*, game_engines.companies.* , game_modes.*, genres.*, involved_companies.*, involved_companies.company.* , keywords.*, multiplayer_modes.*, multiplayer_modes.platform.*, platforms.*, platforms.platform_logo.*, platforms.platform_family.*, platforms.versions.*, platforms.websites.* , player_perspectives.*, release_dates.*, release_dates.platform.*, release_dates.status.* , screenshots.*, themes.*, videos.*, websites.*, language_supports.*, language_supports.language.*, language_supports.language_support_type.* , game_localizations.*, game_localizations.region.* , collections.*, collections.type.*, collections.as_parent_relations.child_collection.*, collections.as_parent_relations.parent_collection.*, collections.as_parent_relations.type.*,collections.as_child_relations.child_collection.*, collections.as_child_relations.parent_collection.*, collections.as_child_relations.type.*, age_ratings.content_descriptions.*, cover.game_localization.*;`, idStr))
if err != nil {
return nil, fmt.Errorf("failed to fetch IGDB games detail for ID %s: %w", idStr, err)
}
res := pb.GameResult{}
if err = proto.Unmarshal(resp.Body(), &res); err != nil {
return nil, fmt.Errorf("failed to unmarshal IGDB games detail response: %w", err)
}
if len(res.Games) == 0 {
return nil, fmt.Errorf("failed to fetch IGDB games detail for ID %s", idStr)
}
if res.Games[0].Name == "" {
return g.GetGames(ids)
}
return res.Games, nil
}

3
go.mod
View File

@@ -1,4 +1,4 @@
module github/bestnite/go-igdb
module github.com/bestnite/go-igdb
go 1.24.1
@@ -6,6 +6,7 @@ require (
github.com/PuerkitoBio/goquery v1.10.2
github.com/bestnite/go-flaresolverr v0.0.0-20250404141941-4644c2e66727
github.com/go-resty/resty/v2 v2.16.5
golang.org/x/time v0.14.0
google.golang.org/protobuf v1.36.6
)

4
go.sum
View File

@@ -367,8 +367,8 @@ golang.org/x/text v0.22.0 h1:bofq7m3/HAFvbF51jz3Q9wLg3jkvSPuiZu/pD1XwgtM=
golang.org/x/text v0.22.0/go.mod h1:YRoo4H8PVmsu+E3Ou7cqLVH8oXWIHVoX0jqUWALQhfY=
golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.6.0 h1:eTDhh4ZXt5Qf0augr54TN6suAUudPcawVZeIAPU7D4U=
golang.org/x/time v0.6.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM=
golang.org/x/time v0.14.0 h1:MRx4UaLrDotUKUdCIqzPC48t1Y9hANFKIRpNx+Te8PI=
golang.org/x/time v0.14.0/go.mod h1:eL/Oa2bBBK0TkX57Fyni+NgnyQQN4LitPmob2Hjnqw4=
golang.org/x/tools v0.0.0-20180828015842-6cd1fcedba52/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20181030000716-a0a13e073c7b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=

49
id.go
View File

@@ -1,49 +0,0 @@
package igdb
import (
"errors"
"fmt"
"github/bestnite/go-igdb/constant"
pb "github/bestnite/go-igdb/proto"
"strconv"
"google.golang.org/protobuf/proto"
)
func (g *igdb) GetGameIDBySteamAppID(id uint64) (uint64, error) {
query := fmt.Sprintf(`where game_type.id = 0 & uid = "%d"; fields game;`, id)
resp, err := g.Request(constant.IGDBExternalGameURL, query)
if err != nil {
return 0, fmt.Errorf("failed to fetch IGDB ID by Steam App ID %d: %w", id, err)
}
res := pb.ExternalGameResult{}
if err = proto.Unmarshal(resp.Body(), &res); err != nil {
return 0, fmt.Errorf("failed to unmarshal IGDB response for Steam App ID %d: %w", id, err)
}
if len(res.Externalgames) == 0 || res.Externalgames[0].Game.Id == 0 {
return 0, errors.New("no matching IGDB game found")
}
return res.Externalgames[0].Game.Id, nil
}
func (g *igdb) GetSteamIDByGameID(id uint64) (uint64, error) {
query := fmt.Sprintf(`where game = %v & game_type.id = 0; fields *;`, id)
resp, err := g.Request(constant.IGDBExternalGameURL, query)
if err != nil {
return 0, fmt.Errorf("failed to fetch IGDB websites for IGDB ID %d: %w", id, err)
}
res := pb.ExternalGameResult{}
if err := proto.Unmarshal(resp.Body(), &res); err != nil {
return 0, fmt.Errorf("failed to unmarshal IGDB websites response for IGDB ID %d: %w", id, err)
}
if len(res.Externalgames) == 0 {
return 0, errors.New("steam ID not found")
}
return strconv.ParseUint(res.Externalgames[0].Uid, 10, 64)
}

56
igdb.go
View File

@@ -1,56 +0,0 @@
package igdb
import (
"fmt"
"github.com/bestnite/go-flaresolverr"
"github.com/go-resty/resty/v2"
)
type igdb struct {
clientID string
token *twitchToken
flaresolverr *flaresolverr.Flaresolverr
}
func New(clientID, clientSecret string) *igdb {
return &igdb{
clientID: clientID,
token: NewTwitchToken(clientID, clientSecret),
flaresolverr: nil,
}
}
func NewWithFlaresolverr(clientID, clientSecret string, f *flaresolverr.Flaresolverr) *igdb {
return &igdb{
clientID: clientID,
token: NewTwitchToken(clientID, clientSecret),
flaresolverr: f,
}
}
func (g *igdb) Request(URL string, dataBody any) (*resty.Response, error) {
t, err := g.token.getToken()
if err != nil {
return nil, fmt.Errorf("failed to get Twitch token: %w", err)
}
resp, err := request().SetBody(dataBody).SetHeaders(map[string]string{
"Client-ID": g.clientID,
"Authorization": "Bearer " + t,
"User-Agent": "",
"Content-Type": "text/plain",
}).Post(URL)
if err != nil {
return nil, fmt.Errorf("failed to make request: %s: %w", URL, err)
}
return resp, nil
}
func (g *igdb) getFlaresolverr() (*flaresolverr.Flaresolverr, error) {
if g.flaresolverr == nil {
return nil, fmt.Errorf("flaresolverr is not initialized")
}
return g.flaresolverr, nil
}

View File

@@ -1,33 +0,0 @@
package igdb
import (
"fmt"
)
func (g *igdb) GetParentGameID(id uint64) (uint64, error) {
detail, err := g.GetGame(id)
if err != nil {
return 0, fmt.Errorf("failed to fetch IGDB app detail for parent: %d: %w", id, err)
}
hasParent := false
if detail.ParentGame != nil && detail.ParentGame.Id != 0 {
hasParent = true
detail, err = g.GetGame(detail.ParentGame.Id)
if err != nil {
return 0, fmt.Errorf("failed to fetch IGDB version parent: %d: %w", detail.VersionParent.Id, err)
}
}
for detail.VersionParent != nil && detail.VersionParent.Id != 0 {
hasParent = true
detail, err = g.GetGame(detail.VersionParent.Id)
if err != nil {
return 0, fmt.Errorf("failed to fetch IGDB version parent: %d: %w", detail.VersionParent.Id, err)
}
}
if hasParent {
return detail.Id, nil
}
return id, nil
}

View File

@@ -1,33 +0,0 @@
package igdb
import (
"fmt"
"github/bestnite/go-igdb/constant"
pb "github/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
)
// GetPopularGameIDs retrieves popular IGDB game IDs based on a given popularity type.
// popularity_type = 1 IGDB Visits: Game page visits on IGDB.com.
// popularity_type = 2 IGDB Want to Play: Additions to IGDB.com users “Want to Play” lists.
// popularity_type = 3 IGDB Playing: Additions to IGDB.com users “Playing” lists.
// popularity_type = 4 IGDB Played: Additions to IGDB.com users “Played” lists.
func (g *igdb) GetPopularGameIDs(popularityType, offset, limit int) ([]uint64, error) {
query := fmt.Sprintf("fields game_id,value,popularity_type; sort value desc; limit %d; offset %d; where popularity_type = %d;", limit, offset, popularityType)
resp, err := g.Request(constant.IGDBPopularityURL, query)
if err != nil {
return nil, fmt.Errorf("failed to fetch popular IGDB game IDs for type %d: %w", popularityType, err)
}
data := pb.PopularityPrimitiveResult{}
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
return nil, fmt.Errorf("failed to unmarshal IGDB popular games response: %w", err)
}
gameIDs := make([]uint64, 0, len(data.Popularityprimitives))
for _, game := range data.Popularityprimitives {
gameIDs = append(gameIDs, uint64(game.GameId))
}
return gameIDs, nil
}

File diff suppressed because it is too large Load Diff

View File

@@ -209,6 +209,19 @@ enum AgeRatingContentDescriptionCategoryEnum {
CLASS_IND_ATOS_CRIMINOSOS = 85 [deprecated = true];
}
message AgeRatingContentDescriptionTypeResult {
repeated AgeRatingContentDescriptionType ageratingcontentdescriptiontypes = 1;
}
message AgeRatingContentDescriptionType {
uint64 id = 1;
string slug = 2;
string name = 3;
google.protobuf.Timestamp created_at = 4;
google.protobuf.Timestamp updated_at = 5;
string checksum = 6;
}
message AgeRatingContentDescriptionV2Result {
repeated AgeRatingContentDescriptionV2 ageratingcontentdescriptionsv2 = 1;
}
@@ -220,6 +233,7 @@ message AgeRatingContentDescriptionV2 {
google.protobuf.Timestamp created_at = 4;
google.protobuf.Timestamp updated_at = 5;
string checksum = 6;
AgeRatingContentDescriptionType description_type = 7;
}
message AgeRatingOrganizationResult {
@@ -260,6 +274,20 @@ message Artwork {
string url = 7;
int32 width = 8;
string checksum = 9;
ArtworkType artwork_type = 10;
}
message ArtworkTypeResult {
repeated ArtworkType artworktypes = 1;
}
message ArtworkType {
uint64 id = 1;
string slug = 2;
string name = 3;
google.protobuf.Timestamp created_at = 4;
google.protobuf.Timestamp updated_at = 5;
string checksum = 6;
}
message CharacterResult {
@@ -1342,6 +1370,7 @@ message ReleaseDate {
ReleaseDateStatus status = 13;
DateFormat date_format = 14;
ReleaseDateRegion release_region = 15;
int32 d = 16;
}
message ReleaseDateRegionResult {

View File

@@ -1,4 +1,4 @@
go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
wget https://api.igdb.com/v4/igdbapi.proto -O ./igdbapi.proto
wget https://api.igdb.com/v4/igdbapi.proto -O ./proto/igdbapi.proto
protoc --go_out=. --go_opt=Mproto/igdbapi.proto=/proto ./proto/igdbapi.proto

149
register_endpoints.go Normal file
View File

@@ -0,0 +1,149 @@
package igdb
import (
"github.com/bestnite/go-igdb/endpoint"
)
func registerAllEndpoints(c *Client) {
c.AgeRatingCategories = endpoint.NewAgeRatingCategories(c.Request)
c.AgeRatingContentDescriptions = endpoint.NewAgeRatingContentDescriptions(c.Request)
c.AgeRatingContentDescriptionsV2 = endpoint.NewAgeRatingContentDescriptionsV2(c.Request)
c.AgeRatingOrganizations = endpoint.NewAgeRatingOrganizations(c.Request)
c.AgeRatings = endpoint.NewAgeRatings(c.Request)
c.AlternativeNames = endpoint.NewAlternativeNames(c.Request)
c.Artworks = endpoint.NewArtworks(c.Request)
c.CharacterGenders = endpoint.NewCharacterGenders(c.Request)
c.CharacterMugShots = endpoint.NewCharacterMugShots(c.Request)
c.Characters = endpoint.NewCharacters(c.Request)
c.CharacterSpecies = endpoint.NewCharacterSpecies(c.Request)
c.CollectionMemberships = endpoint.NewCollectionMemberships(c.Request)
c.CollectionMembershipTypes = endpoint.NewCollectionMembershipTypes(c.Request)
c.CollectionRelations = endpoint.NewCollectionRelations(c.Request)
c.CollectionRelationTypes = endpoint.NewCollectionRelationTypes(c.Request)
c.Collections = endpoint.NewCollections(c.Request)
c.CollectionTypes = endpoint.NewCollectionTypes(c.Request)
c.Companies = endpoint.NewCompanies(c.Request)
c.CompanyLogos = endpoint.NewCompanyLogos(c.Request)
c.CompanyStatuses = endpoint.NewCompanyStatuses(c.Request)
c.CompanyWebsites = endpoint.NewCompanyWebsites(c.Request)
c.Covers = endpoint.NewCovers(c.Request)
c.DateFormats = endpoint.NewDateFormats(c.Request)
c.EventLogos = endpoint.NewEventLogos(c.Request)
c.EventNetworks = endpoint.NewEventNetworks(c.Request)
c.Events = endpoint.NewEvents(c.Request)
c.ExternalGames = endpoint.NewExternalGames(c.Request)
c.ExternalGameSources = endpoint.NewExternalGameSources(c.Request)
c.Franchises = endpoint.NewFranchises(c.Request)
c.GameEngineLogos = endpoint.NewGameEngineLogos(c.Request)
c.GameEngines = endpoint.NewGameEngines(c.Request)
c.GameLocalizations = endpoint.NewGameLocalizations(c.Request)
c.GameModes = endpoint.NewGameModes(c.Request)
c.GameReleaseFormats = endpoint.NewGameReleaseFormats(c.Request)
c.Games = endpoint.NewGames(c.Request)
c.GameStatuses = endpoint.NewGameStatuses(c.Request)
c.GameTimeToBeats = endpoint.NewGameTimeToBeats(c.Request)
c.GameTypes = endpoint.NewGameTypes(c.Request)
c.GameVersionFeatures = endpoint.NewGameVersionFeatures(c.Request)
c.GameVersionFeatureValues = endpoint.NewGameVersionFeatureValues(c.Request)
c.GameVersions = endpoint.NewGameVersions(c.Request)
c.GameVideos = endpoint.NewGameVideos(c.Request)
c.Genres = endpoint.NewGenres(c.Request)
c.InvolvedCompanies = endpoint.NewInvolvedCompanies(c.Request)
c.Keywords = endpoint.NewKeywords(c.Request)
c.Languages = endpoint.NewLanguages(c.Request)
c.LanguageSupports = endpoint.NewLanguageSupports(c.Request)
c.LanguageSupportTypes = endpoint.NewLanguageSupportTypes(c.Request)
c.MultiplayerModes = endpoint.NewMultiplayerModes(c.Request)
c.NetworkTypes = endpoint.NewNetworkTypes(c.Request)
c.PlatformFamilies = endpoint.NewPlatformFamilies(c.Request)
c.PlatformLogos = endpoint.NewPlatformLogos(c.Request)
c.Platforms = endpoint.NewPlatforms(c.Request)
c.PlatformTypes = endpoint.NewPlatformTypes(c.Request)
c.PlatformVersionCompanies = endpoint.NewPlatformVersionCompanies(c.Request)
c.PlatformVersionReleaseDates = endpoint.NewPlatformVersionReleaseDates(c.Request)
c.PlatformVersions = endpoint.NewPlatformVersions(c.Request)
c.PlatformWebsites = endpoint.NewPlatformWebsites(c.Request)
c.PlayerPerspectives = endpoint.NewPlayerPerspectives(c.Request)
c.PopularityPrimitives = endpoint.NewPopularityPrimitives(c.Request)
c.PopularityTypes = endpoint.NewPopularityTypes(c.Request)
c.Regions = endpoint.NewRegions(c.Request)
c.ReleaseDateRegions = endpoint.NewReleaseDateRegions(c.Request)
c.ReleaseDates = endpoint.NewReleaseDates(c.Request)
c.ReleaseDateStatuses = endpoint.NewReleaseDateStatuses(c.Request)
c.Screenshots = endpoint.NewScreenshots(c.Request)
c.Themes = endpoint.NewThemes(c.Request)
c.Websites = endpoint.NewWebsites(c.Request)
c.WebsiteTypes = endpoint.NewWebsiteTypes(c.Request)
c.Webhooks = endpoint.NewWebhooks(c.Request)
c.Search = endpoint.NewSearch(c.Request)
}

View File

@@ -7,23 +7,19 @@ import (
"github.com/go-resty/resty/v2"
)
var client *resty.Client
type SilentLogger struct{}
func init() {
client = resty.New()
client.SetRetryCount(3).SetRetryWaitTime(3 * time.Second).AddRetryCondition(
func (s SilentLogger) Errorf(string, ...any) {}
func (s SilentLogger) Warnf(string, ...any) {}
func (s SilentLogger) Debugf(string, ...any) {}
func NewRestyClient() *resty.Client {
return resty.New().SetRetryCount(10).SetRetryWaitTime(3 * time.Second).AddRetryCondition(
func(r *resty.Response, err error) bool {
return err != nil || r.StatusCode() == http.StatusTooManyRequests
if err != nil || r.StatusCode() == http.StatusTooManyRequests {
return true
}
return false
},
)
}
func request() *resty.Request {
return client.R().SetLogger(disableLogger{}).SetHeader("Accept-Charset", "utf-8").SetHeader("User-Agent", "Mozilla/5.0 (X11; Linux x86_64; rv:133.0) Gecko/20100101 Firefox/133.0")
}
type disableLogger struct{}
func (d disableLogger) Errorf(format string, v ...interface{}) {}
func (d disableLogger) Warnf(format string, v ...interface{}) {}
func (d disableLogger) Debugf(format string, v ...interface{}) {}

View File

@@ -1,9 +1,9 @@
package igdb
import (
"context"
"encoding/json"
"fmt"
"github/bestnite/go-igdb/constant"
"net/url"
"time"
)
@@ -15,18 +15,18 @@ type twitchToken struct {
expires time.Time
}
func NewTwitchToken(clientID, clientSecret string) *twitchToken {
func newTwitchToken(clientID, clientSecret string) *twitchToken {
return &twitchToken{
clientID: clientID,
clientSecret: clientSecret,
}
}
func (t *twitchToken) getToken() (string, error) {
func (t *twitchToken) GetToken(ctx context.Context) (string, error) {
if t.token != "" && time.Now().Before(t.expires) {
return t.token, nil
}
token, expires, err := t.loginTwitch()
token, expires, err := t.LoginTwitch(ctx)
if err != nil {
return "", fmt.Errorf("failed to login twitch: %w", err)
}
@@ -35,15 +35,15 @@ func (t *twitchToken) getToken() (string, error) {
return token, nil
}
func (t *twitchToken) loginTwitch() (string, time.Duration, error) {
baseURL, _ := url.Parse(constant.TwitchAuthURL)
func (t *twitchToken) LoginTwitch(ctx context.Context) (string, time.Duration, error) {
baseURL, _ := url.Parse("https://id.twitch.tv/oauth2/token")
params := url.Values{}
params.Add("client_id", t.clientID)
params.Add("client_secret", t.clientSecret)
params.Add("grant_type", "client_credentials")
baseURL.RawQuery = params.Encode()
resp, err := request().SetHeader("User-Agent", "").Post(baseURL.String())
resp, err := NewRestyClient().R().SetContext(ctx).SetHeader("User-Agent", "").Post(baseURL.String())
if err != nil {
return "", 0, fmt.Errorf("failed to make request: %s: %w", baseURL.String(), err)
}

View File

@@ -1,37 +0,0 @@
package igdb
import (
"fmt"
"github/bestnite/go-igdb/constant"
"net/http"
"net/url"
)
// ActiveWebhook activates a webhook for a specific endpoint.
//
// https://api-docs.igdb.com/#webhooks
func (g *igdb) ActiveWebhook(endpoint, secret, callbackUrl string) error {
t, err := g.token.getToken()
if err != nil {
return fmt.Errorf("failed to get Twitch token: %w", err)
}
dataBody := url.Values{}
dataBody.Set("url", callbackUrl)
dataBody.Set("secret", secret)
dataBody.Set("method", "update")
resp, err := request().SetBody(dataBody.Encode()).SetHeaders(map[string]string{
"Client-ID": g.clientID,
"Authorization": "Bearer " + t,
"User-Agent": "",
"Content-Type": "application/x-www-form-urlencoded",
}).Post(fmt.Sprintf(constant.IGDBWebhookURL, endpoint))
if err != nil {
return fmt.Errorf("failed to make request: %s: %w", callbackUrl, err)
}
if resp.StatusCode() == http.StatusOK {
return nil
}
return fmt.Errorf("failed to activate webhook: %s: %s", callbackUrl, resp.String())
}