12 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
87 changed files with 4207 additions and 4181 deletions

1
.gitignore vendored
View File

@@ -1,3 +1,4 @@
*test.go *test.go
test/ test/
.vscode/ .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.

View File

@@ -26,11 +26,10 @@ import (
"log" "log"
"github.com/bestnite/go-igdb" "github.com/bestnite/go-igdb"
pb "github.com/bestnite/go-igdb/proto"
) )
func Test1(c *igdb.Client) { func Test1(c *igdb.Client) {
game, err := igdb.GetItemByID[pb.Game](1942, c.Games.Query) game, err := c.Games.GetByID(1942)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
@@ -38,7 +37,7 @@ func Test1(c *igdb.Client) {
} }
func Test2(c *igdb.Client) { func Test2(c *igdb.Client) {
games, err := igdb.GetItemsByIDs[pb.Game]([]uint64{119171, 119133}, c.Games.Query) games, err := c.Games.GetByIDs([]uint64{119171, 119133})
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
@@ -46,7 +45,7 @@ func Test2(c *igdb.Client) {
} }
func Test3(c *igdb.Client) { func Test3(c *igdb.Client) {
total, err := igdb.GetItemsLength[pb.Game](c.Games.Query) total, err := c.Games.Count()
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
@@ -54,7 +53,7 @@ func Test3(c *igdb.Client) {
} }
func Test4(c *igdb.Client) { func Test4(c *igdb.Client) {
games, err := igdb.GetItemsPagniated[pb.Game](0, 10, c.Games.Query) games, err := c.Games.Paginated(0, 10)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
@@ -65,15 +64,15 @@ func Test4(c *igdb.Client) {
} }
func Test5(c *igdb.Client) { func Test5(c *igdb.Client) {
game, err := igdb.AssertSingle[pb.Game](c.Games.Query("fields name,rating; sort rating desc; limit 1;")) game, err := c.Games.Query("fields name,rating; sort rating desc; limit 1;")
if err != nil { if err != nil {
log.Fatalf("failed to get game: %s", err) log.Fatalf("failed to get game: %s", err)
} }
log.Printf("Name of first game with highest rating: %s\n", game.Name) log.Printf("Name of first game with highest rating: %s\n", game[0].Name)
} }
func Test6(c *igdb.Client) { func Test6(c *igdb.Client) {
games, err := igdb.AssertSlice[pb.Game](c.Games.Query("fields *; where rating > 70; limit 10;")) games, err := c.Games.Query("fields *; where rating > 70; limit 10;")
if err != nil { if err != nil {
panic(err) panic(err)
} }
@@ -94,21 +93,21 @@ func main() {
} }
``` ```
## Advanced Usage ## Example Projects
### Using with FlareSolverr - [igdb-database](https://github.com/bestnite/igdb-database)
```go ## Dependencies
import "github.com/bestnite/go-flaresolverr"
flaresolverr := flaresolverr.New("http://localhost:8191") - [go-resty/resty](https://github.com/go-resty/resty)
client := igdb.NewWithFlaresolverr("your-client-id", "your-client-secret", flaresolverr) - [google/protobuf](https://github.com/google/protobuf)
``` - [bestnite/go-flaresolverr](https://github.com/bestnite/go-flaresolverr)
- [PuerkitoBio/goquery](https://github.com/PuerkitoBio/goquery)
### Rate Limiting
The client automatically handles rate limiting with a default of 4 requests per second. This helps prevent hitting IGDB's rate limits.
## Contributing ## Contributing
Contributions are welcome! Please feel free to submit a Pull Request. 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.

View File

@@ -1,41 +0,0 @@
package igdb
import "fmt"
func AssertSingle[T any](data any, err error) (*T, error) {
if err != nil {
return nil, err
}
if data == nil {
return nil, fmt.Errorf("data is nil")
}
datas, ok := data.([]*T)
if !ok {
return nil, fmt.Errorf("failed to convert to []*T")
}
if len(datas) == 0 {
return nil, fmt.Errorf("no results")
}
return datas[0], nil
}
func AssertSlice[T any](data any, err error) ([]*T, error) {
if err != nil {
return nil, err
}
if data == nil {
return nil, fmt.Errorf("data is nil")
}
datas, ok := data.([]*T)
if !ok {
return nil, fmt.Errorf("failed to convert to []*T")
}
return datas, nil
}

View File

@@ -1,11 +1,13 @@
package igdb package igdb
import ( import (
"context"
"fmt" "fmt"
"strings" "strings"
"github.com/bestnite/go-flaresolverr" "github.com/bestnite/go-flaresolverr"
"github.com/bestnite/go-igdb/endpoint" "github.com/bestnite/go-igdb/endpoint"
"golang.org/x/time/rate"
"github.com/go-resty/resty/v2" "github.com/go-resty/resty/v2"
) )
@@ -14,9 +16,8 @@ type Client struct {
clientID string clientID string
token *twitchToken token *twitchToken
flaresolverr *flaresolverr.Flaresolverr flaresolverr *flaresolverr.Flaresolverr
limiter *rateLimiter restyClient *resty.Client
limiter *rate.Limiter
EntityEndpoints map[endpoint.EndpointName]endpoint.EntityEndpoint
AgeRatingCategories *endpoint.AgeRatingCategories AgeRatingCategories *endpoint.AgeRatingCategories
AgeRatingContentDescriptions *endpoint.AgeRatingContentDescriptions AgeRatingContentDescriptions *endpoint.AgeRatingContentDescriptions
@@ -94,104 +95,48 @@ type Client struct {
func New(clientID, clientSecret string) *Client { func New(clientID, clientSecret string) *Client {
c := &Client{ c := &Client{
clientID: clientID, clientID: clientID,
limiter: newRateLimiter(4), restyClient: NewRestyClient(),
token: NewTwitchToken(clientID, clientSecret), token: newTwitchToken(clientID, clientSecret),
flaresolverr: nil, flaresolverr: nil,
EntityEndpoints: make(map[endpoint.EndpointName]endpoint.EntityEndpoint), limiter: rate.NewLimiter(rate.Limit(4), 4),
} }
registerAllEndpoints(c) registerAllEndpoints(c)
return c return c
} }
type RequestFunc func(method string, URL string, dataBody any) (*resty.Response, error)
func NewWithFlaresolverr(clientID, clientSecret string, f *flaresolverr.Flaresolverr) *Client { func NewWithFlaresolverr(clientID, clientSecret string, f *flaresolverr.Flaresolverr) *Client {
c := New(clientID, clientSecret) c := New(clientID, clientSecret)
c.flaresolverr = f c.flaresolverr = f
return c return c
} }
func (g *Client) Request(URL string, dataBody any) (*resty.Response, error) { func (g *Client) Request(ctx context.Context, method string, URL string, dataBody any) (*resty.Response, error) {
g.limiter.wait() 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() t, err := g.token.GetToken(ctx)
if err != nil { if err != nil {
return nil, fmt.Errorf("failed to get twitch token: %w", err) return nil, fmt.Errorf("failed to get twitch token: %w", err)
} }
resp, err := request().SetBody(dataBody).SetHeaders(map[string]string{ resp, err := g.restyClient.R().SetContext(ctx).SetBody(dataBody).SetHeaders(map[string]string{
"Client-ID": g.clientID, "Client-ID": g.clientID,
"Authorization": "Bearer " + t, "Authorization": "Bearer " + t,
"User-Agent": "", "User-Agent": "",
"Content-Type": "text/plain", "Content-Type": "text/plain",
}).Post(URL) }).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 { if err != nil {
return nil, fmt.Errorf("failed to request: %s: %w", URL, err) return nil, fmt.Errorf("failed to request: %s: %w", URL, err)
} }
return resp, nil return resp, nil
} }
func GetItemsPagniated[T any](offset, limit int, f func(string) ([]*T, error)) ([]*T, error) {
query := fmt.Sprintf("offset %d; limit %d; f *; sort id asc;", offset, limit)
items, err := f(query)
if err != nil {
return nil, err
}
return items, nil
}
func GetItemsLength[T any](f func(string) ([]*T, error)) (uint64, error) {
query := "fields id; sort id desc; limit 1;"
items, err := f(query)
if err != nil {
return 0, err
}
if len(items) == 0 {
return 0, fmt.Errorf("no results: %s", query)
}
type Iid interface {
GetId() uint64
}
item, ok := any(items[0]).(Iid)
if !ok {
return 0, fmt.Errorf("failed to convert")
}
return item.GetId(), nil
}
func GetItemByID[T any](id uint64, f func(string) ([]*T, error)) (*T, error) {
query := fmt.Sprintf("where id = %d; fields *;", id)
items, err := f(query)
if err != nil {
return nil, err
}
if len(items) == 0 {
return nil, fmt.Errorf("no results: %s", query)
}
return items[0], nil
}
func GetItemsByIDs[T any](ids []uint64, f func(string) ([]*T, error)) ([]*T, error) {
idStrSlice := make([]string, len(ids))
for i, id := range ids {
idStrSlice[i] = fmt.Sprintf("%d", id)
}
idStr := fmt.Sprintf(`where id = (%s); fields *;`, strings.Join(idStrSlice, ","))
items, err := f(idStr)
if err != nil {
return nil, err
}
return items, nil
}

View File

@@ -1,6 +1,7 @@
package endpoint package endpoint
import ( import (
"context"
"fmt" "fmt"
pb "github.com/bestnite/go-igdb/proto" pb "github.com/bestnite/go-igdb/proto"
@@ -9,11 +10,22 @@ import (
) )
type AgeRatingCategories struct { type AgeRatingCategories struct {
BaseEndpoint BaseEndpoint[pb.AgeRatingCategory]
} }
func (a *AgeRatingCategories) Query(query string) ([]*pb.AgeRatingCategory, error) { func NewAgeRatingCategories(request RequestFunc) *AgeRatingCategories {
resp, err := a.request("https://api.igdb.com/v4/age_rating_categories.pb", query) 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 { if err != nil {
return nil, fmt.Errorf("failed to request: %w", err) return nil, fmt.Errorf("failed to request: %w", err)
} }

View File

@@ -1,6 +1,7 @@
package endpoint package endpoint
import ( import (
"context"
"fmt" "fmt"
pb "github.com/bestnite/go-igdb/proto" pb "github.com/bestnite/go-igdb/proto"
@@ -9,11 +10,22 @@ import (
) )
type AgeRatingContentDescriptions struct { type AgeRatingContentDescriptions struct {
BaseEndpoint BaseEndpoint[pb.AgeRatingContentDescription]
} }
func (a *AgeRatingContentDescriptions) Query(query string) ([]*pb.AgeRatingContentDescription, error) { func NewAgeRatingContentDescriptions(request RequestFunc) *AgeRatingContentDescriptions {
resp, err := a.request("https://api.igdb.com/v4/age_rating_content_descriptions.pb", query) 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 { if err != nil {
return nil, fmt.Errorf("failed to request: %w", err) return nil, fmt.Errorf("failed to request: %w", err)
} }

View File

@@ -1,6 +1,7 @@
package endpoint package endpoint
import ( import (
"context"
"fmt" "fmt"
pb "github.com/bestnite/go-igdb/proto" pb "github.com/bestnite/go-igdb/proto"
@@ -9,11 +10,22 @@ import (
) )
type AgeRatingContentDescriptionsV2 struct { type AgeRatingContentDescriptionsV2 struct {
BaseEndpoint BaseEndpoint[pb.AgeRatingContentDescriptionV2]
} }
func (a *AgeRatingContentDescriptionsV2) Query(query string) ([]*pb.AgeRatingContentDescriptionV2, error) { func NewAgeRatingContentDescriptionsV2(request RequestFunc) *AgeRatingContentDescriptionsV2 {
resp, err := a.request("https://api.igdb.com/v4/age_rating_content_descriptions_v2.pb", query) 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 { if err != nil {
return nil, fmt.Errorf("failed to request: %w", err) return nil, fmt.Errorf("failed to request: %w", err)
} }

View File

@@ -1,6 +1,7 @@
package endpoint package endpoint
import ( import (
"context"
"fmt" "fmt"
pb "github.com/bestnite/go-igdb/proto" pb "github.com/bestnite/go-igdb/proto"
@@ -8,10 +9,23 @@ import (
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
) )
type AgeRatingOrganizations struct{ BaseEndpoint } type AgeRatingOrganizations struct {
BaseEndpoint[pb.AgeRatingOrganization]
}
func (a *AgeRatingOrganizations) Query(query string) ([]*pb.AgeRatingOrganization, error) { func NewAgeRatingOrganizations(request RequestFunc) *AgeRatingOrganizations {
resp, err := a.request("https://api.igdb.com/v4/age_rating_organizations.pb", query) 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 { if err != nil {
return nil, fmt.Errorf("failed to request: %w", err) return nil, fmt.Errorf("failed to request: %w", err)
} }

View File

@@ -1,6 +1,7 @@
package endpoint package endpoint
import ( import (
"context"
"fmt" "fmt"
pb "github.com/bestnite/go-igdb/proto" pb "github.com/bestnite/go-igdb/proto"
@@ -8,10 +9,23 @@ import (
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
) )
type AgeRatings struct{ BaseEndpoint } type AgeRatings struct {
BaseEndpoint[pb.AgeRating]
}
func (a *AgeRatings) Query(query string) ([]*pb.AgeRating, error) { func NewAgeRatings(request RequestFunc) *AgeRatings {
resp, err := a.request("https://api.igdb.com/v4/age_ratings.pb", query) 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 { if err != nil {
return nil, fmt.Errorf("failed to request: %w", err) return nil, fmt.Errorf("failed to request: %w", err)
} }

View File

@@ -1,6 +1,7 @@
package endpoint package endpoint
import ( import (
"context"
"fmt" "fmt"
pb "github.com/bestnite/go-igdb/proto" pb "github.com/bestnite/go-igdb/proto"
@@ -8,10 +9,23 @@ import (
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
) )
type AlternativeNames struct{ BaseEndpoint } type AlternativeNames struct {
BaseEndpoint[pb.AlternativeName]
}
func (a *AlternativeNames) Query(query string) ([]*pb.AlternativeName, error) { func NewAlternativeNames(request RequestFunc) *AlternativeNames {
resp, err := a.request("https://api.igdb.com/v4/alternative_names.pb", query) 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 { if err != nil {
return nil, fmt.Errorf("failed to request: %w", err) return nil, fmt.Errorf("failed to request: %w", err)
} }

View File

@@ -1,6 +1,7 @@
package endpoint package endpoint
import ( import (
"context"
"fmt" "fmt"
pb "github.com/bestnite/go-igdb/proto" pb "github.com/bestnite/go-igdb/proto"
@@ -8,10 +9,23 @@ import (
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
) )
type Artworks struct{ BaseEndpoint } type Artworks struct {
BaseEndpoint[pb.Artwork]
}
func (a *Artworks) Query(query string) ([]*pb.Artwork, error) { func NewArtworks(request RequestFunc) *Artworks {
resp, err := a.request("https://api.igdb.com/v4/artworks.pb", query) 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 { if err != nil {
return nil, fmt.Errorf("failed to request: %w", err) return nil, fmt.Errorf("failed to request: %w", err)
} }

View File

@@ -1,38 +1,97 @@
package endpoint package endpoint
import ( import (
"context"
"fmt"
"strconv"
"strings"
pb "github.com/bestnite/go-igdb/proto"
"google.golang.org/protobuf/proto"
"github.com/go-resty/resty/v2" "github.com/go-resty/resty/v2"
) )
type BaseEndpoint struct { type RequestFunc func(ctx context.Context, method string, URL string, dataBody any) (*resty.Response, error)
request func(URL string, dataBody any) (*resty.Response, error)
endpointName EndpointName type BaseEndpoint[T any] struct {
request RequestFunc
endpointName Name
queryFunc func(context.Context, string) ([]*T, error)
} }
func NewBaseEndpoint(request func(URL string, dataBody any) (*resty.Response, error), endpointName EndpointName) *BaseEndpoint { func (b *BaseEndpoint[T]) GetEndpointName() Name {
return &BaseEndpoint{
request: request,
endpointName: endpointName,
}
}
func (b *BaseEndpoint) GetEndpointName() EndpointName {
return b.endpointName return b.endpointName
} }
func (b *BaseEndpoint) Query(query string) (any, error) { func (b *BaseEndpoint[T]) Query(ctx context.Context, query string) ([]*T, error) {
return nil, nil if b.queryFunc == nil {
return nil, fmt.Errorf("query method must be implemented by specific endpoint")
}
return b.queryFunc(ctx, query)
} }
func (b *BaseEndpoint) QueryAny(query string) (any, error) { func (b *BaseEndpoint[T]) GetByID(ctx context.Context, id uint64) (*T, error) {
return b.Query(query) 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
} }
type Endpoint interface { func (b *BaseEndpoint[T]) GetByIDs(ctx context.Context, ids []uint64) ([]*T, error) {
GetEndpointName() EndpointName 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
} }
type EntityEndpoint interface { func (b *BaseEndpoint[T]) Count(ctx context.Context) (uint64, error) {
QueryAny(query string) (any, error) resp, err := b.request(ctx, "POST", fmt.Sprintf("https://api.igdb.com/v4/%s/count.pb", b.endpointName), "")
GetEndpointName() 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

@@ -1,6 +1,7 @@
package endpoint package endpoint
import ( import (
"context"
"fmt" "fmt"
pb "github.com/bestnite/go-igdb/proto" pb "github.com/bestnite/go-igdb/proto"
@@ -8,10 +9,23 @@ import (
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
) )
type CharacterGenders struct{ BaseEndpoint } type CharacterGenders struct {
BaseEndpoint[pb.CharacterGender]
}
func (a *CharacterGenders) Query(query string) ([]*pb.CharacterGender, error) { func NewCharacterGenders(request RequestFunc) *CharacterGenders {
resp, err := a.request("https://api.igdb.com/v4/character_genders.pb", query) 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 { if err != nil {
return nil, fmt.Errorf("failed to request: %w", err) return nil, fmt.Errorf("failed to request: %w", err)
} }

View File

@@ -1,6 +1,7 @@
package endpoint package endpoint
import ( import (
"context"
"fmt" "fmt"
pb "github.com/bestnite/go-igdb/proto" pb "github.com/bestnite/go-igdb/proto"
@@ -8,10 +9,23 @@ import (
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
) )
type CharacterMugShots struct{ BaseEndpoint } type CharacterMugShots struct {
BaseEndpoint[pb.CharacterMugShot]
}
func (a *CharacterMugShots) Query(query string) ([]*pb.CharacterMugShot, error) { func NewCharacterMugShots(request RequestFunc) *CharacterMugShots {
resp, err := a.request("https://api.igdb.com/v4/character_mug_shots.pb", query) 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 { if err != nil {
return nil, fmt.Errorf("failed to request: %w", err) return nil, fmt.Errorf("failed to request: %w", err)
} }

View File

@@ -1,6 +1,7 @@
package endpoint package endpoint
import ( import (
"context"
"fmt" "fmt"
pb "github.com/bestnite/go-igdb/proto" pb "github.com/bestnite/go-igdb/proto"
@@ -8,10 +9,23 @@ import (
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
) )
type CharacterSpecies struct{ BaseEndpoint } type CharacterSpecies struct {
BaseEndpoint[pb.CharacterSpecie]
}
func (a *CharacterSpecies) Query(query string) ([]*pb.CharacterSpecie, error) { func NewCharacterSpecies(request RequestFunc) *CharacterSpecies {
resp, err := a.request("https://api.igdb.com/v4/character_species.pb", query) 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 { if err != nil {
return nil, fmt.Errorf("failed to request: %w", err) return nil, fmt.Errorf("failed to request: %w", err)
} }

View File

@@ -1,6 +1,7 @@
package endpoint package endpoint
import ( import (
"context"
"fmt" "fmt"
pb "github.com/bestnite/go-igdb/proto" pb "github.com/bestnite/go-igdb/proto"
@@ -8,10 +9,23 @@ import (
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
) )
type Characters struct{ BaseEndpoint } type Characters struct {
BaseEndpoint[pb.Character]
}
func (a *Characters) Query(query string) ([]*pb.Character, error) { func NewCharacters(request RequestFunc) *Characters {
resp, err := a.request("https://api.igdb.com/v4/characters.pb", query) 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 { if err != nil {
return nil, fmt.Errorf("failed to request: %w", err) return nil, fmt.Errorf("failed to request: %w", err)
} }

View File

@@ -1,6 +1,7 @@
package endpoint package endpoint
import ( import (
"context"
"fmt" "fmt"
pb "github.com/bestnite/go-igdb/proto" pb "github.com/bestnite/go-igdb/proto"
@@ -8,10 +9,23 @@ import (
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
) )
type CollectionMembershipTypes struct{ BaseEndpoint } type CollectionMembershipTypes struct {
BaseEndpoint[pb.CollectionMembershipType]
}
func (a *CollectionMembershipTypes) Query(query string) ([]*pb.CollectionMembershipType, error) { func NewCollectionMembershipTypes(request RequestFunc) *CollectionMembershipTypes {
resp, err := a.request("https://api.igdb.com/v4/collection_membership_types.pb", query) 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 { if err != nil {
return nil, fmt.Errorf("failed to request: %w", err) return nil, fmt.Errorf("failed to request: %w", err)
} }

View File

@@ -1,6 +1,7 @@
package endpoint package endpoint
import ( import (
"context"
"fmt" "fmt"
pb "github.com/bestnite/go-igdb/proto" pb "github.com/bestnite/go-igdb/proto"
@@ -8,10 +9,23 @@ import (
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
) )
type CollectionMemberships struct{ BaseEndpoint } type CollectionMemberships struct {
BaseEndpoint[pb.CollectionMembership]
}
func (a *CollectionMemberships) Query(query string) ([]*pb.CollectionMembership, error) { func NewCollectionMemberships(request RequestFunc) *CollectionMemberships {
resp, err := a.request("https://api.igdb.com/v4/collection_memberships.pb", query) 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 { if err != nil {
return nil, fmt.Errorf("failed to request: %w", err) return nil, fmt.Errorf("failed to request: %w", err)
} }

View File

@@ -1,6 +1,7 @@
package endpoint package endpoint
import ( import (
"context"
"fmt" "fmt"
pb "github.com/bestnite/go-igdb/proto" pb "github.com/bestnite/go-igdb/proto"
@@ -8,10 +9,23 @@ import (
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
) )
type CollectionRelationTypes struct{ BaseEndpoint } type CollectionRelationTypes struct {
BaseEndpoint[pb.CollectionRelationType]
}
func (a *CollectionRelationTypes) Query(query string) ([]*pb.CollectionRelationType, error) { func NewCollectionRelationTypes(request RequestFunc) *CollectionRelationTypes {
resp, err := a.request("https://api.igdb.com/v4/collection_relation_types.pb", query) 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 { if err != nil {
return nil, fmt.Errorf("failed to request: %w", err) return nil, fmt.Errorf("failed to request: %w", err)
} }

View File

@@ -1,6 +1,7 @@
package endpoint package endpoint
import ( import (
"context"
"fmt" "fmt"
pb "github.com/bestnite/go-igdb/proto" pb "github.com/bestnite/go-igdb/proto"
@@ -8,10 +9,23 @@ import (
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
) )
type CollectionRelations struct{ BaseEndpoint } type CollectionRelations struct {
BaseEndpoint[pb.CollectionRelation]
}
func (a *CollectionRelations) Query(query string) ([]*pb.CollectionRelation, error) { func NewCollectionRelations(request RequestFunc) *CollectionRelations {
resp, err := a.request("https://api.igdb.com/v4/collection_relations.pb", query) 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 { if err != nil {
return nil, fmt.Errorf("failed to request: %w", err) return nil, fmt.Errorf("failed to request: %w", err)
} }

View File

@@ -1,6 +1,7 @@
package endpoint package endpoint
import ( import (
"context"
"fmt" "fmt"
pb "github.com/bestnite/go-igdb/proto" pb "github.com/bestnite/go-igdb/proto"
@@ -8,10 +9,23 @@ import (
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
) )
type CollectionTypes struct{ BaseEndpoint } type CollectionTypes struct {
BaseEndpoint[pb.CollectionType]
}
func (a *CollectionTypes) Query(query string) ([]*pb.CollectionType, error) { func NewCollectionTypes(request RequestFunc) *CollectionTypes {
resp, err := a.request("https://api.igdb.com/v4/collection_types.pb", query) 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 { if err != nil {
return nil, fmt.Errorf("failed to request: %w", err) return nil, fmt.Errorf("failed to request: %w", err)
} }

View File

@@ -1,6 +1,7 @@
package endpoint package endpoint
import ( import (
"context"
"fmt" "fmt"
pb "github.com/bestnite/go-igdb/proto" pb "github.com/bestnite/go-igdb/proto"
@@ -8,10 +9,23 @@ import (
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
) )
type Collections struct{ BaseEndpoint } type Collections struct {
BaseEndpoint[pb.Collection]
}
func (a *Collections) Query(query string) ([]*pb.Collection, error) { func NewCollections(request RequestFunc) *Collections {
resp, err := a.request("https://api.igdb.com/v4/collections.pb", query) 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 { if err != nil {
return nil, fmt.Errorf("failed to request: %w", err) return nil, fmt.Errorf("failed to request: %w", err)
} }

View File

@@ -1,6 +1,7 @@
package endpoint package endpoint
import ( import (
"context"
"errors" "errors"
"fmt" "fmt"
@@ -9,10 +10,23 @@ import (
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
) )
type Companies struct{ BaseEndpoint } type Companies struct {
BaseEndpoint[pb.Company]
}
func (a *Companies) Query(query string) ([]*pb.Company, error) { func NewCompanies(request RequestFunc) *Companies {
resp, err := a.request("https://api.igdb.com/v4/companies.pb", query) 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 { if err != nil {
return nil, fmt.Errorf("failed to request: %w", err) return nil, fmt.Errorf("failed to request: %w", err)
} }

View File

@@ -1,6 +1,7 @@
package endpoint package endpoint
import ( import (
"context"
"fmt" "fmt"
pb "github.com/bestnite/go-igdb/proto" pb "github.com/bestnite/go-igdb/proto"
@@ -8,10 +9,23 @@ import (
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
) )
type CompanyLogos struct{ BaseEndpoint } type CompanyLogos struct {
BaseEndpoint[pb.CompanyLogo]
}
func (a *CompanyLogos) Query(query string) ([]*pb.CompanyLogo, error) { func NewCompanyLogos(request RequestFunc) *CompanyLogos {
resp, err := a.request("https://api.igdb.com/v4/company_logos.pb", query) 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 { if err != nil {
return nil, fmt.Errorf("failed to request: %w", err) return nil, fmt.Errorf("failed to request: %w", err)
} }

View File

@@ -1,6 +1,7 @@
package endpoint package endpoint
import ( import (
"context"
"fmt" "fmt"
pb "github.com/bestnite/go-igdb/proto" pb "github.com/bestnite/go-igdb/proto"
@@ -8,10 +9,23 @@ import (
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
) )
type CompanyStatuses struct{ BaseEndpoint } type CompanyStatuses struct {
BaseEndpoint[pb.CompanyStatus]
}
func (a *CompanyStatuses) Query(query string) ([]*pb.CompanyStatus, error) { func NewCompanyStatuses(request RequestFunc) *CompanyStatuses {
resp, err := a.request("https://api.igdb.com/v4/company_statuses.pb", query) 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 { if err != nil {
return nil, fmt.Errorf("failed to request: %w", err) return nil, fmt.Errorf("failed to request: %w", err)
} }

View File

@@ -1,6 +1,7 @@
package endpoint package endpoint
import ( import (
"context"
"fmt" "fmt"
pb "github.com/bestnite/go-igdb/proto" pb "github.com/bestnite/go-igdb/proto"
@@ -8,10 +9,23 @@ import (
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
) )
type CompanyWebsites struct{ BaseEndpoint } type CompanyWebsites struct {
BaseEndpoint[pb.CompanyWebsite]
}
func (a *CompanyWebsites) Query(query string) ([]*pb.CompanyWebsite, error) { func NewCompanyWebsites(request RequestFunc) *CompanyWebsites {
resp, err := a.request("https://api.igdb.com/v4/company_websites.pb", query) 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 { if err != nil {
return nil, fmt.Errorf("failed to request: %w", err) return nil, fmt.Errorf("failed to request: %w", err)
} }

View File

@@ -1,6 +1,7 @@
package endpoint package endpoint
import ( import (
"context"
"fmt" "fmt"
pb "github.com/bestnite/go-igdb/proto" pb "github.com/bestnite/go-igdb/proto"
@@ -8,10 +9,23 @@ import (
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
) )
type Covers struct{ BaseEndpoint } type Covers struct {
BaseEndpoint[pb.Cover]
}
func (a *Covers) Query(query string) ([]*pb.Cover, error) { func NewCovers(request RequestFunc) *Covers {
resp, err := a.request("https://api.igdb.com/v4/covers.pb", query) 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 { if err != nil {
return nil, fmt.Errorf("failed to request: %w", err) return nil, fmt.Errorf("failed to request: %w", err)
} }

View File

@@ -1,6 +1,7 @@
package endpoint package endpoint
import ( import (
"context"
"fmt" "fmt"
pb "github.com/bestnite/go-igdb/proto" pb "github.com/bestnite/go-igdb/proto"
@@ -8,10 +9,23 @@ import (
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
) )
type DateFormats struct{ BaseEndpoint } type DateFormats struct {
BaseEndpoint[pb.DateFormat]
}
func (a *DateFormats) Query(query string) ([]*pb.DateFormat, error) { func NewDateFormats(request RequestFunc) *DateFormats {
resp, err := a.request("https://api.igdb.com/v4/date_formats.pb", query) 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 { if err != nil {
return nil, fmt.Errorf("failed to request: %w", err) return nil, fmt.Errorf("failed to request: %w", err)
} }

View File

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

View File

@@ -1,6 +1,7 @@
package endpoint package endpoint
import ( import (
"context"
"fmt" "fmt"
pb "github.com/bestnite/go-igdb/proto" pb "github.com/bestnite/go-igdb/proto"
@@ -8,10 +9,23 @@ import (
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
) )
type EventLogos struct{ BaseEndpoint } type EventLogos struct {
BaseEndpoint[pb.EventLogo]
}
func (a *EventLogos) Query(query string) ([]*pb.EventLogo, error) { func NewEventLogos(request RequestFunc) *EventLogos {
resp, err := a.request("https://api.igdb.com/v4/event_logos.pb", query) 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 { if err != nil {
return nil, fmt.Errorf("failed to request: %w", err) return nil, fmt.Errorf("failed to request: %w", err)
} }

View File

@@ -1,6 +1,7 @@
package endpoint package endpoint
import ( import (
"context"
"fmt" "fmt"
pb "github.com/bestnite/go-igdb/proto" pb "github.com/bestnite/go-igdb/proto"
@@ -8,10 +9,23 @@ import (
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
) )
type EventNetworks struct{ BaseEndpoint } type EventNetworks struct {
BaseEndpoint[pb.EventNetwork]
}
func (a *EventNetworks) Query(query string) ([]*pb.EventNetwork, error) { func NewEventNetworks(request RequestFunc) *EventNetworks {
resp, err := a.request("https://api.igdb.com/v4/event_networks.pb", query) 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 { if err != nil {
return nil, fmt.Errorf("failed to request: %w", err) return nil, fmt.Errorf("failed to request: %w", err)
} }

View File

@@ -1,6 +1,7 @@
package endpoint package endpoint
import ( import (
"context"
"fmt" "fmt"
pb "github.com/bestnite/go-igdb/proto" pb "github.com/bestnite/go-igdb/proto"
@@ -8,10 +9,23 @@ import (
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
) )
type Events struct{ BaseEndpoint } type Events struct {
BaseEndpoint[pb.Event]
}
func (a *Events) Query(query string) ([]*pb.Event, error) { func NewEvents(request RequestFunc) *Events {
resp, err := a.request("https://api.igdb.com/v4/events.pb", query) 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 { if err != nil {
return nil, fmt.Errorf("failed to request: %w", err) return nil, fmt.Errorf("failed to request: %w", err)
} }

View File

@@ -1,6 +1,7 @@
package endpoint package endpoint
import ( import (
"context"
"fmt" "fmt"
pb "github.com/bestnite/go-igdb/proto" pb "github.com/bestnite/go-igdb/proto"
@@ -8,10 +9,23 @@ import (
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
) )
type ExternalGameSources struct{ BaseEndpoint } type ExternalGameSources struct {
BaseEndpoint[pb.ExternalGameSource]
}
func (a *ExternalGameSources) Query(query string) ([]*pb.ExternalGameSource, error) { func NewExternalGameSources(request RequestFunc) *ExternalGameSources {
resp, err := a.request("https://api.igdb.com/v4/external_game_sources.pb", query) 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 { if err != nil {
return nil, fmt.Errorf("failed to request: %w", err) return nil, fmt.Errorf("failed to request: %w", err)
} }

View File

@@ -1,6 +1,7 @@
package endpoint package endpoint
import ( import (
"context"
"fmt" "fmt"
pb "github.com/bestnite/go-igdb/proto" pb "github.com/bestnite/go-igdb/proto"
@@ -8,10 +9,23 @@ import (
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
) )
type ExternalGames struct{ BaseEndpoint } type ExternalGames struct {
BaseEndpoint[pb.ExternalGame]
}
func (a *ExternalGames) Query(query string) ([]*pb.ExternalGame, error) { func NewExternalGames(request RequestFunc) *ExternalGames {
resp, err := a.request("https://api.igdb.com/v4/external_games.pb", query) 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 { if err != nil {
return nil, fmt.Errorf("failed to request: %w", err) return nil, fmt.Errorf("failed to request: %w", err)
} }

View File

@@ -1,6 +1,7 @@
package endpoint package endpoint
import ( import (
"context"
"fmt" "fmt"
pb "github.com/bestnite/go-igdb/proto" pb "github.com/bestnite/go-igdb/proto"
@@ -8,10 +9,23 @@ import (
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
) )
type Franchises struct{ BaseEndpoint } type Franchises struct {
BaseEndpoint[pb.Franchise]
}
func (a *Franchises) Query(query string) ([]*pb.Franchise, error) { func NewFranchises(request RequestFunc) *Franchises {
resp, err := a.request("https://api.igdb.com/v4/franchises.pb", query) 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 { if err != nil {
return nil, fmt.Errorf("failed to request: %w", err) return nil, fmt.Errorf("failed to request: %w", err)
} }

View File

@@ -1,6 +1,7 @@
package endpoint package endpoint
import ( import (
"context"
"fmt" "fmt"
pb "github.com/bestnite/go-igdb/proto" pb "github.com/bestnite/go-igdb/proto"
@@ -8,10 +9,23 @@ import (
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
) )
type GameEngineLogos struct{ BaseEndpoint } type GameEngineLogos struct {
BaseEndpoint[pb.GameEngineLogo]
}
func (a *GameEngineLogos) Query(query string) ([]*pb.GameEngineLogo, error) { func NewGameEngineLogos(request RequestFunc) *GameEngineLogos {
resp, err := a.request("https://api.igdb.com/v4/game_engine_logos.pb", query) 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 { if err != nil {
return nil, fmt.Errorf("failed to request: %w", err) return nil, fmt.Errorf("failed to request: %w", err)
} }

View File

@@ -1,6 +1,7 @@
package endpoint package endpoint
import ( import (
"context"
"fmt" "fmt"
pb "github.com/bestnite/go-igdb/proto" pb "github.com/bestnite/go-igdb/proto"
@@ -8,10 +9,23 @@ import (
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
) )
type GameEngines struct{ BaseEndpoint } type GameEngines struct {
BaseEndpoint[pb.GameEngine]
}
func (a *GameEngines) Query(query string) ([]*pb.GameEngine, error) { func NewGameEngines(request RequestFunc) *GameEngines {
resp, err := a.request("https://api.igdb.com/v4/game_engines.pb", query) 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 { if err != nil {
return nil, fmt.Errorf("failed to request: %w", err) return nil, fmt.Errorf("failed to request: %w", err)
} }

View File

@@ -1,6 +1,7 @@
package endpoint package endpoint
import ( import (
"context"
"fmt" "fmt"
pb "github.com/bestnite/go-igdb/proto" pb "github.com/bestnite/go-igdb/proto"
@@ -8,10 +9,23 @@ import (
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
) )
type GameLocalizations struct{ BaseEndpoint } type GameLocalizations struct {
BaseEndpoint[pb.GameLocalization]
}
func (a *GameLocalizations) Query(query string) ([]*pb.GameLocalization, error) { func NewGameLocalizations(request RequestFunc) *GameLocalizations {
resp, err := a.request("https://api.igdb.com/v4/game_localizations.pb", query) 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 { if err != nil {
return nil, fmt.Errorf("failed to request: %w", err) return nil, fmt.Errorf("failed to request: %w", err)
} }

View File

@@ -1,6 +1,7 @@
package endpoint package endpoint
import ( import (
"context"
"fmt" "fmt"
pb "github.com/bestnite/go-igdb/proto" pb "github.com/bestnite/go-igdb/proto"
@@ -8,10 +9,23 @@ import (
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
) )
type GameModes struct{ BaseEndpoint } type GameModes struct {
BaseEndpoint[pb.GameMode]
}
func (a *GameModes) Query(query string) ([]*pb.GameMode, error) { func NewGameModes(request RequestFunc) *GameModes {
resp, err := a.request("https://api.igdb.com/v4/game_modes.pb", query) 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 { if err != nil {
return nil, fmt.Errorf("failed to request: %w", err) return nil, fmt.Errorf("failed to request: %w", err)
} }

View File

@@ -1,6 +1,7 @@
package endpoint package endpoint
import ( import (
"context"
"fmt" "fmt"
pb "github.com/bestnite/go-igdb/proto" pb "github.com/bestnite/go-igdb/proto"
@@ -8,10 +9,23 @@ import (
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
) )
type GameReleaseFormats struct{ BaseEndpoint } type GameReleaseFormats struct {
BaseEndpoint[pb.GameReleaseFormat]
}
func (a *GameReleaseFormats) Query(query string) ([]*pb.GameReleaseFormat, error) { func NewGameReleaseFormats(request RequestFunc) *GameReleaseFormats {
resp, err := a.request("https://api.igdb.com/v4/game_release_formats.pb", query) 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 { if err != nil {
return nil, fmt.Errorf("failed to request: %w", err) return nil, fmt.Errorf("failed to request: %w", err)
} }

View File

@@ -1,6 +1,7 @@
package endpoint package endpoint
import ( import (
"context"
"fmt" "fmt"
pb "github.com/bestnite/go-igdb/proto" pb "github.com/bestnite/go-igdb/proto"
@@ -8,10 +9,23 @@ import (
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
) )
type GameStatuses struct{ BaseEndpoint } type GameStatuses struct {
BaseEndpoint[pb.GameStatus]
}
func (a *GameStatuses) Query(query string) ([]*pb.GameStatus, error) { func NewGameStatuses(request RequestFunc) *GameStatuses {
resp, err := a.request("https://api.igdb.com/v4/game_statuses.pb", query) 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 { if err != nil {
return nil, fmt.Errorf("failed to request: %w", err) return nil, fmt.Errorf("failed to request: %w", err)
} }

View File

@@ -1,6 +1,7 @@
package endpoint package endpoint
import ( import (
"context"
"fmt" "fmt"
pb "github.com/bestnite/go-igdb/proto" pb "github.com/bestnite/go-igdb/proto"
@@ -8,10 +9,23 @@ import (
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
) )
type GameTimeToBeats struct{ BaseEndpoint } type GameTimeToBeats struct {
BaseEndpoint[pb.GameTimeToBeat]
}
func (a *GameTimeToBeats) Query(query string) ([]*pb.GameTimeToBeat, error) { func NewGameTimeToBeats(request RequestFunc) *GameTimeToBeats {
resp, err := a.request("https://api.igdb.com/v4/game_time_to_beats.pb", query) 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 { if err != nil {
return nil, fmt.Errorf("failed to request: %w", err) return nil, fmt.Errorf("failed to request: %w", err)
} }

View File

@@ -1,6 +1,7 @@
package endpoint package endpoint
import ( import (
"context"
"fmt" "fmt"
pb "github.com/bestnite/go-igdb/proto" pb "github.com/bestnite/go-igdb/proto"
@@ -8,10 +9,23 @@ import (
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
) )
type GameTypes struct{ BaseEndpoint } type GameTypes struct {
BaseEndpoint[pb.GameType]
}
func (a *GameTypes) Query(query string) ([]*pb.GameType, error) { func NewGameTypes(request RequestFunc) *GameTypes {
resp, err := a.request("https://api.igdb.com/v4/game_types.pb", query) 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 { if err != nil {
return nil, fmt.Errorf("failed to request: %w", err) return nil, fmt.Errorf("failed to request: %w", err)
} }

View File

@@ -1,6 +1,7 @@
package endpoint package endpoint
import ( import (
"context"
"fmt" "fmt"
pb "github.com/bestnite/go-igdb/proto" pb "github.com/bestnite/go-igdb/proto"
@@ -8,10 +9,23 @@ import (
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
) )
type GameVersionFeatureValues struct{ BaseEndpoint } type GameVersionFeatureValues struct {
BaseEndpoint[pb.GameVersionFeatureValue]
}
func (a *GameVersionFeatureValues) Query(query string) ([]*pb.GameVersionFeatureValue, error) { func NewGameVersionFeatureValues(request RequestFunc) *GameVersionFeatureValues {
resp, err := a.request("https://api.igdb.com/v4/game_version_feature_values.pb", query) 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 { if err != nil {
return nil, fmt.Errorf("failed to request: %w", err) return nil, fmt.Errorf("failed to request: %w", err)
} }

View File

@@ -1,6 +1,7 @@
package endpoint package endpoint
import ( import (
"context"
"fmt" "fmt"
pb "github.com/bestnite/go-igdb/proto" pb "github.com/bestnite/go-igdb/proto"
@@ -8,10 +9,23 @@ import (
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
) )
type GameVersionFeatures struct{ BaseEndpoint } type GameVersionFeatures struct {
BaseEndpoint[pb.GameVersionFeature]
}
func (a *GameVersionFeatures) Query(query string) ([]*pb.GameVersionFeature, error) { func NewGameVersionFeatures(request RequestFunc) *GameVersionFeatures {
resp, err := a.request("https://api.igdb.com/v4/game_version_features.pb", query) 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 { if err != nil {
return nil, fmt.Errorf("failed to request: %w", err) return nil, fmt.Errorf("failed to request: %w", err)
} }

View File

@@ -1,6 +1,7 @@
package endpoint package endpoint
import ( import (
"context"
"fmt" "fmt"
pb "github.com/bestnite/go-igdb/proto" pb "github.com/bestnite/go-igdb/proto"
@@ -8,10 +9,23 @@ import (
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
) )
type GameVersions struct{ BaseEndpoint } type GameVersions struct {
BaseEndpoint[pb.GameVersion]
}
func (a *GameVersions) Query(query string) ([]*pb.GameVersion, error) { func NewGameVersions(request RequestFunc) *GameVersions {
resp, err := a.request("https://api.igdb.com/v4/game_versions.pb", query) 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 { if err != nil {
return nil, fmt.Errorf("failed to request: %w", err) return nil, fmt.Errorf("failed to request: %w", err)
} }

View File

@@ -1,6 +1,7 @@
package endpoint package endpoint
import ( import (
"context"
"fmt" "fmt"
pb "github.com/bestnite/go-igdb/proto" pb "github.com/bestnite/go-igdb/proto"
@@ -8,10 +9,23 @@ import (
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
) )
type GameVideos struct{ BaseEndpoint } type GameVideos struct {
BaseEndpoint[pb.GameVideo]
}
func (a *GameVideos) Query(query string) ([]*pb.GameVideo, error) { func NewGameVideos(request RequestFunc) *GameVideos {
resp, err := a.request("https://api.igdb.com/v4/game_videos.pb", query) 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 { if err != nil {
return nil, fmt.Errorf("failed to request: %w", err) return nil, fmt.Errorf("failed to request: %w", err)
} }

View File

@@ -1,6 +1,7 @@
package endpoint package endpoint
import ( import (
"context"
"fmt" "fmt"
pb "github.com/bestnite/go-igdb/proto" pb "github.com/bestnite/go-igdb/proto"
@@ -8,10 +9,23 @@ import (
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
) )
type Games struct{ BaseEndpoint } type Games struct {
BaseEndpoint[pb.Game]
}
func (a *Games) Query(query string) ([]*pb.Game, error) { func NewGames(request RequestFunc) *Games {
resp, err := a.request("https://api.igdb.com/v4/games.pb", query) 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 { if err != nil {
return nil, fmt.Errorf("failed to request: %w", err) return nil, fmt.Errorf("failed to request: %w", err)
} }

View File

@@ -1,6 +1,7 @@
package endpoint package endpoint
import ( import (
"context"
"fmt" "fmt"
pb "github.com/bestnite/go-igdb/proto" pb "github.com/bestnite/go-igdb/proto"
@@ -8,10 +9,23 @@ import (
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
) )
type Genres struct{ BaseEndpoint } type Genres struct {
BaseEndpoint[pb.Genre]
}
func (a *Genres) Query(query string) ([]*pb.Genre, error) { func NewGenres(request RequestFunc) *Genres {
resp, err := a.request("https://api.igdb.com/v4/genres.pb", query) 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 { if err != nil {
return nil, fmt.Errorf("failed to request: %w", err) return nil, fmt.Errorf("failed to request: %w", err)
} }

View File

@@ -1,6 +1,7 @@
package endpoint package endpoint
import ( import (
"context"
"fmt" "fmt"
pb "github.com/bestnite/go-igdb/proto" pb "github.com/bestnite/go-igdb/proto"
@@ -8,10 +9,23 @@ import (
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
) )
type InvolvedCompanies struct{ BaseEndpoint } type InvolvedCompanies struct {
BaseEndpoint[pb.InvolvedCompany]
}
func (a *InvolvedCompanies) Query(query string) ([]*pb.InvolvedCompany, error) { func NewInvolvedCompanies(request RequestFunc) *InvolvedCompanies {
resp, err := a.request("https://api.igdb.com/v4/involved_companies.pb", query) 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 { if err != nil {
return nil, fmt.Errorf("failed to request: %w", err) return nil, fmt.Errorf("failed to request: %w", err)
} }

View File

@@ -1,6 +1,7 @@
package endpoint package endpoint
import ( import (
"context"
"fmt" "fmt"
pb "github.com/bestnite/go-igdb/proto" pb "github.com/bestnite/go-igdb/proto"
@@ -8,10 +9,23 @@ import (
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
) )
type Keywords struct{ BaseEndpoint } type Keywords struct {
BaseEndpoint[pb.Keyword]
}
func (a *Keywords) Query(query string) ([]*pb.Keyword, error) { func NewKeywords(request RequestFunc) *Keywords {
resp, err := a.request("https://api.igdb.com/v4/keywords.pb", query) 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 { if err != nil {
return nil, fmt.Errorf("failed to request: %w", err) return nil, fmt.Errorf("failed to request: %w", err)
} }

View File

@@ -1,6 +1,7 @@
package endpoint package endpoint
import ( import (
"context"
"fmt" "fmt"
pb "github.com/bestnite/go-igdb/proto" pb "github.com/bestnite/go-igdb/proto"
@@ -8,10 +9,23 @@ import (
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
) )
type LanguageSupportTypes struct{ BaseEndpoint } type LanguageSupportTypes struct {
BaseEndpoint[pb.LanguageSupportType]
}
func (a *LanguageSupportTypes) Query(query string) ([]*pb.LanguageSupportType, error) { func NewLanguageSupportTypes(request RequestFunc) *LanguageSupportTypes {
resp, err := a.request("https://api.igdb.com/v4/language_support_types.pb", query) 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 { if err != nil {
return nil, fmt.Errorf("failed to request: %w", err) return nil, fmt.Errorf("failed to request: %w", err)
} }

View File

@@ -1,6 +1,7 @@
package endpoint package endpoint
import ( import (
"context"
"fmt" "fmt"
pb "github.com/bestnite/go-igdb/proto" pb "github.com/bestnite/go-igdb/proto"
@@ -8,10 +9,23 @@ import (
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
) )
type LanguageSupports struct{ BaseEndpoint } type LanguageSupports struct {
BaseEndpoint[pb.LanguageSupport]
}
func (a *LanguageSupports) Query(query string) ([]*pb.LanguageSupport, error) { func NewLanguageSupports(request RequestFunc) *LanguageSupports {
resp, err := a.request("https://api.igdb.com/v4/language_supports.pb", query) 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 { if err != nil {
return nil, fmt.Errorf("failed to request: %w", err) return nil, fmt.Errorf("failed to request: %w", err)
} }

View File

@@ -1,6 +1,7 @@
package endpoint package endpoint
import ( import (
"context"
"fmt" "fmt"
pb "github.com/bestnite/go-igdb/proto" pb "github.com/bestnite/go-igdb/proto"
@@ -8,10 +9,23 @@ import (
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
) )
type Languages struct{ BaseEndpoint } type Languages struct {
BaseEndpoint[pb.Language]
}
func (a *Languages) Query(query string) ([]*pb.Language, error) { func NewLanguages(request RequestFunc) *Languages {
resp, err := a.request("https://api.igdb.com/v4/languages.pb", query) 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 { if err != nil {
return nil, fmt.Errorf("failed to request: %w", err) return nil, fmt.Errorf("failed to request: %w", err)
} }

View File

@@ -1,6 +1,7 @@
package endpoint package endpoint
import ( import (
"context"
"fmt" "fmt"
pb "github.com/bestnite/go-igdb/proto" pb "github.com/bestnite/go-igdb/proto"
@@ -8,10 +9,23 @@ import (
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
) )
type MultiplayerModes struct{ BaseEndpoint } type MultiplayerModes struct {
BaseEndpoint[pb.MultiplayerMode]
}
func (a *MultiplayerModes) Query(query string) ([]*pb.MultiplayerMode, error) { func NewMultiplayerModes(request RequestFunc) *MultiplayerModes {
resp, err := a.request("https://api.igdb.com/v4/multiplayer_modes.pb", query) 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 { if err != nil {
return nil, fmt.Errorf("failed to request: %w", err) return nil, fmt.Errorf("failed to request: %w", err)
} }

View File

@@ -1,6 +1,7 @@
package endpoint package endpoint
import ( import (
"context"
"fmt" "fmt"
pb "github.com/bestnite/go-igdb/proto" pb "github.com/bestnite/go-igdb/proto"
@@ -8,10 +9,23 @@ import (
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
) )
type NetworkTypes struct{ BaseEndpoint } type NetworkTypes struct {
BaseEndpoint[pb.NetworkType]
}
func (a *NetworkTypes) Query(query string) ([]*pb.NetworkType, error) { func NewNetworkTypes(request RequestFunc) *NetworkTypes {
resp, err := a.request("https://api.igdb.com/v4/network_types.pb", query) 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 { if err != nil {
return nil, fmt.Errorf("failed to request: %w", err) return nil, fmt.Errorf("failed to request: %w", err)
} }

View File

@@ -1,6 +1,7 @@
package endpoint package endpoint
import ( import (
"context"
"fmt" "fmt"
pb "github.com/bestnite/go-igdb/proto" pb "github.com/bestnite/go-igdb/proto"
@@ -8,10 +9,23 @@ import (
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
) )
type PlatformFamilies struct{ BaseEndpoint } type PlatformFamilies struct {
BaseEndpoint[pb.PlatformFamily]
}
func (a *PlatformFamilies) Query(query string) ([]*pb.PlatformFamily, error) { func NewPlatformFamilies(request RequestFunc) *PlatformFamilies {
resp, err := a.request("https://api.igdb.com/v4/platform_families.pb", query) 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 { if err != nil {
return nil, fmt.Errorf("failed to request: %w", err) return nil, fmt.Errorf("failed to request: %w", err)
} }

View File

@@ -1,6 +1,7 @@
package endpoint package endpoint
import ( import (
"context"
"fmt" "fmt"
pb "github.com/bestnite/go-igdb/proto" pb "github.com/bestnite/go-igdb/proto"
@@ -8,10 +9,23 @@ import (
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
) )
type PlatformLogos struct{ BaseEndpoint } type PlatformLogos struct {
BaseEndpoint[pb.PlatformLogo]
}
func (a *PlatformLogos) Query(query string) ([]*pb.PlatformLogo, error) { func NewPlatformLogos(request RequestFunc) *PlatformLogos {
resp, err := a.request("https://api.igdb.com/v4/platform_logos.pb", query) 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 { if err != nil {
return nil, fmt.Errorf("failed to request: %w", err) return nil, fmt.Errorf("failed to request: %w", err)
} }

View File

@@ -1,6 +1,7 @@
package endpoint package endpoint
import ( import (
"context"
"fmt" "fmt"
pb "github.com/bestnite/go-igdb/proto" pb "github.com/bestnite/go-igdb/proto"
@@ -8,10 +9,23 @@ import (
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
) )
type PlatformTypes struct{ BaseEndpoint } type PlatformTypes struct {
BaseEndpoint[pb.PlatformType]
}
func (a *PlatformTypes) Query(query string) ([]*pb.PlatformType, error) { func NewPlatformTypes(request RequestFunc) *PlatformTypes {
resp, err := a.request("https://api.igdb.com/v4/platform_types.pb", query) 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 { if err != nil {
return nil, fmt.Errorf("failed to request: %w", err) return nil, fmt.Errorf("failed to request: %w", err)
} }

View File

@@ -1,6 +1,7 @@
package endpoint package endpoint
import ( import (
"context"
"fmt" "fmt"
pb "github.com/bestnite/go-igdb/proto" pb "github.com/bestnite/go-igdb/proto"
@@ -8,10 +9,23 @@ import (
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
) )
type PlatformVersionCompanies struct{ BaseEndpoint } type PlatformVersionCompanies struct {
BaseEndpoint[pb.PlatformVersionCompany]
}
func (a *PlatformVersionCompanies) Query(query string) ([]*pb.PlatformVersionCompany, error) { func NewPlatformVersionCompanies(request RequestFunc) *PlatformVersionCompanies {
resp, err := a.request("https://api.igdb.com/v4/platform_version_companies.pb", query) 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 { if err != nil {
return nil, fmt.Errorf("failed to request: %w", err) return nil, fmt.Errorf("failed to request: %w", err)
} }

View File

@@ -1,6 +1,7 @@
package endpoint package endpoint
import ( import (
"context"
"fmt" "fmt"
pb "github.com/bestnite/go-igdb/proto" pb "github.com/bestnite/go-igdb/proto"
@@ -8,10 +9,23 @@ import (
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
) )
type PlatformVersionReleaseDates struct{ BaseEndpoint } type PlatformVersionReleaseDates struct {
BaseEndpoint[pb.PlatformVersionReleaseDate]
}
func (a *PlatformVersionReleaseDates) Query(query string) ([]*pb.PlatformVersionReleaseDate, error) { func NewPlatformVersionReleaseDates(request RequestFunc) *PlatformVersionReleaseDates {
resp, err := a.request("https://api.igdb.com/v4/platform_version_release_dates.pb", query) 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 { if err != nil {
return nil, fmt.Errorf("failed to request: %w", err) return nil, fmt.Errorf("failed to request: %w", err)
} }

View File

@@ -1,6 +1,7 @@
package endpoint package endpoint
import ( import (
"context"
"fmt" "fmt"
pb "github.com/bestnite/go-igdb/proto" pb "github.com/bestnite/go-igdb/proto"
@@ -8,10 +9,23 @@ import (
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
) )
type PlatformVersions struct{ BaseEndpoint } type PlatformVersions struct {
BaseEndpoint[pb.PlatformVersion]
}
func (a *PlatformVersions) Query(query string) ([]*pb.PlatformVersion, error) { func NewPlatformVersions(request RequestFunc) *PlatformVersions {
resp, err := a.request("https://api.igdb.com/v4/platform_versions.pb", query) 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 { if err != nil {
return nil, fmt.Errorf("failed to request: %w", err) return nil, fmt.Errorf("failed to request: %w", err)
} }

View File

@@ -1,6 +1,7 @@
package endpoint package endpoint
import ( import (
"context"
"fmt" "fmt"
pb "github.com/bestnite/go-igdb/proto" pb "github.com/bestnite/go-igdb/proto"
@@ -8,10 +9,23 @@ import (
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
) )
type PlatformWebsites struct{ BaseEndpoint } type PlatformWebsites struct {
BaseEndpoint[pb.PlatformWebsite]
}
func (a *PlatformWebsites) Query(query string) ([]*pb.PlatformWebsite, error) { func NewPlatformWebsites(request RequestFunc) *PlatformWebsites {
resp, err := a.request("https://api.igdb.com/v4/platform_websites.pb", query) 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 { if err != nil {
return nil, fmt.Errorf("failed to request: %w", err) return nil, fmt.Errorf("failed to request: %w", err)
} }

View File

@@ -1,6 +1,7 @@
package endpoint package endpoint
import ( import (
"context"
"fmt" "fmt"
pb "github.com/bestnite/go-igdb/proto" pb "github.com/bestnite/go-igdb/proto"
@@ -8,10 +9,23 @@ import (
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
) )
type Platforms struct{ BaseEndpoint } type Platforms struct {
BaseEndpoint[pb.Platform]
}
func (a *Platforms) Query(query string) ([]*pb.Platform, error) { func NewPlatforms(request RequestFunc) *Platforms {
resp, err := a.request("https://api.igdb.com/v4/platforms.pb", query) 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 { if err != nil {
return nil, fmt.Errorf("failed to request: %w", err) return nil, fmt.Errorf("failed to request: %w", err)
} }

View File

@@ -1,6 +1,7 @@
package endpoint package endpoint
import ( import (
"context"
"fmt" "fmt"
pb "github.com/bestnite/go-igdb/proto" pb "github.com/bestnite/go-igdb/proto"
@@ -8,10 +9,23 @@ import (
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
) )
type PlayerPerspectives struct{ BaseEndpoint } type PlayerPerspectives struct {
BaseEndpoint[pb.PlayerPerspective]
}
func (a *PlayerPerspectives) Query(query string) ([]*pb.PlayerPerspective, error) { func NewPlayerPerspectives(request RequestFunc) *PlayerPerspectives {
resp, err := a.request("https://api.igdb.com/v4/player_perspectives.pb", query) 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 { if err != nil {
return nil, fmt.Errorf("failed to request: %w", err) return nil, fmt.Errorf("failed to request: %w", err)
} }

View File

@@ -1,6 +1,7 @@
package endpoint package endpoint
import ( import (
"context"
"fmt" "fmt"
pb "github.com/bestnite/go-igdb/proto" pb "github.com/bestnite/go-igdb/proto"
@@ -8,10 +9,23 @@ import (
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
) )
type PopularityPrimitives struct{ BaseEndpoint } type PopularityPrimitives struct {
BaseEndpoint[pb.PopularityPrimitive]
}
func (a *PopularityPrimitives) Query(query string) ([]*pb.PopularityPrimitive, error) { func NewPopularityPrimitives(request RequestFunc) *PopularityPrimitives {
resp, err := a.request("https://api.igdb.com/v4/popularity_primitives.pb", query) 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 { if err != nil {
return nil, fmt.Errorf("failed to request: %w", err) return nil, fmt.Errorf("failed to request: %w", err)
} }

View File

@@ -1,6 +1,7 @@
package endpoint package endpoint
import ( import (
"context"
"fmt" "fmt"
pb "github.com/bestnite/go-igdb/proto" pb "github.com/bestnite/go-igdb/proto"
@@ -8,10 +9,23 @@ import (
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
) )
type PopularityTypes struct{ BaseEndpoint } type PopularityTypes struct {
BaseEndpoint[pb.PopularityType]
}
func (a *PopularityTypes) Query(query string) ([]*pb.PopularityType, error) { func NewPopularityTypes(request RequestFunc) *PopularityTypes {
resp, err := a.request("https://api.igdb.com/v4/popularity_types.pb", query) 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 { if err != nil {
return nil, fmt.Errorf("failed to request: %w", err) return nil, fmt.Errorf("failed to request: %w", err)
} }

View File

@@ -1,6 +1,7 @@
package endpoint package endpoint
import ( import (
"context"
"fmt" "fmt"
pb "github.com/bestnite/go-igdb/proto" pb "github.com/bestnite/go-igdb/proto"
@@ -8,10 +9,23 @@ import (
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
) )
type Regions struct{ BaseEndpoint } type Regions struct {
BaseEndpoint[pb.Region]
}
func (a *Regions) Query(query string) ([]*pb.Region, error) { func NewRegions(request RequestFunc) *Regions {
resp, err := a.request("https://api.igdb.com/v4/regions.pb", query) 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 { if err != nil {
return nil, fmt.Errorf("failed to request: %w", err) return nil, fmt.Errorf("failed to request: %w", err)
} }

View File

@@ -1,6 +1,7 @@
package endpoint package endpoint
import ( import (
"context"
"fmt" "fmt"
pb "github.com/bestnite/go-igdb/proto" pb "github.com/bestnite/go-igdb/proto"
@@ -8,10 +9,23 @@ import (
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
) )
type ReleaseDateRegions struct{ BaseEndpoint } type ReleaseDateRegions struct {
BaseEndpoint[pb.ReleaseDateRegion]
}
func (a *ReleaseDateRegions) Query(query string) ([]*pb.ReleaseDateRegion, error) { func NewReleaseDateRegions(request RequestFunc) *ReleaseDateRegions {
resp, err := a.request("https://api.igdb.com/v4/release_date_regions.pb", query) 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 { if err != nil {
return nil, fmt.Errorf("failed to request: %w", err) return nil, fmt.Errorf("failed to request: %w", err)
} }

View File

@@ -1,6 +1,7 @@
package endpoint package endpoint
import ( import (
"context"
"fmt" "fmt"
pb "github.com/bestnite/go-igdb/proto" pb "github.com/bestnite/go-igdb/proto"
@@ -8,10 +9,23 @@ import (
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
) )
type ReleaseDateStatuses struct{ BaseEndpoint } type ReleaseDateStatuses struct {
BaseEndpoint[pb.ReleaseDateStatus]
}
func (a *ReleaseDateStatuses) Query(query string) ([]*pb.ReleaseDateStatus, error) { func NewReleaseDateStatuses(request RequestFunc) *ReleaseDateStatuses {
resp, err := a.request("https://api.igdb.com/v4/release_date_statuses.pb", query) 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 { if err != nil {
return nil, fmt.Errorf("failed to request: %w", err) return nil, fmt.Errorf("failed to request: %w", err)
} }

View File

@@ -1,6 +1,7 @@
package endpoint package endpoint
import ( import (
"context"
"fmt" "fmt"
pb "github.com/bestnite/go-igdb/proto" pb "github.com/bestnite/go-igdb/proto"
@@ -8,10 +9,23 @@ import (
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
) )
type ReleaseDates struct{ BaseEndpoint } type ReleaseDates struct {
BaseEndpoint[pb.ReleaseDate]
}
func (a *ReleaseDates) Query(query string) ([]*pb.ReleaseDate, error) { func NewReleaseDates(request RequestFunc) *ReleaseDates {
resp, err := a.request("https://api.igdb.com/v4/release_dates.pb", query) 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 { if err != nil {
return nil, fmt.Errorf("failed to request: %w", err) return nil, fmt.Errorf("failed to request: %w", err)
} }

View File

@@ -1,6 +1,7 @@
package endpoint package endpoint
import ( import (
"context"
"fmt" "fmt"
pb "github.com/bestnite/go-igdb/proto" pb "github.com/bestnite/go-igdb/proto"
@@ -8,10 +9,23 @@ import (
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
) )
type Screenshots struct{ BaseEndpoint } type Screenshots struct {
BaseEndpoint[pb.Screenshot]
}
func (a *Screenshots) Query(query string) ([]*pb.Screenshot, error) { func NewScreenshots(request RequestFunc) *Screenshots {
resp, err := a.request("https://api.igdb.com/v4/screenshots.pb", query) 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 { if err != nil {
return nil, fmt.Errorf("failed to request: %w", err) return nil, fmt.Errorf("failed to request: %w", err)
} }

View File

@@ -1,6 +1,7 @@
package endpoint package endpoint
import ( import (
"context"
"encoding/json" "encoding/json"
"fmt" "fmt"
"io" "io"
@@ -22,12 +23,20 @@ var webSearchCFCookies struct {
} }
type Search struct { type Search struct {
BaseEndpoint endpointName Name
request RequestFunc
flaresolverr *flaresolverr.Flaresolverr flaresolverr *flaresolverr.Flaresolverr
} }
func (a *Search) Search(query string) ([]*pb.Search, error) { func NewSearch(request RequestFunc) *Search {
resp, err := a.request("https://api.igdb.com/v4/search.pb", query) 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 { if err != nil {
return nil, fmt.Errorf("failed to request: %w", err) return nil, fmt.Errorf("failed to request: %w", err)
} }

View File

@@ -1,6 +1,7 @@
package endpoint package endpoint
import ( import (
"context"
"fmt" "fmt"
pb "github.com/bestnite/go-igdb/proto" pb "github.com/bestnite/go-igdb/proto"
@@ -8,10 +9,23 @@ import (
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
) )
type Themes struct{ BaseEndpoint } type Themes struct {
BaseEndpoint[pb.Theme]
}
func (a *Themes) Query(query string) ([]*pb.Theme, error) { func NewThemes(request RequestFunc) *Themes {
resp, err := a.request("https://api.igdb.com/v4/themes.pb", query) 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 { if err != nil {
return nil, fmt.Errorf("failed to request: %w", err) return nil, fmt.Errorf("failed to request: %w", err)
} }

View File

@@ -1,26 +1,104 @@
package endpoint package endpoint
import ( import (
"context"
"encoding/json"
"fmt" "fmt"
"net/http" "net/http"
"net/url" "net/url"
) )
type Webhooks struct{ BaseEndpoint } type Webhooks struct {
request RequestFunc
}
func (a *Webhooks) Register(endpoint EndpointName, secret, callbackUrl string) error { 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 := url.Values{}
dataBody.Set("url", callbackUrl) dataBody.Set("url", callbackUrl)
dataBody.Set("secret", secret) dataBody.Set("secret", secret)
dataBody.Set("method", "update") dataBody.Set("method", string(method))
resp, err := a.request(fmt.Sprintf("https://api.igdb.com/v4/%s/webhooks/", endpoint), dataBody.Encode())
resp, err := a.request(ctx, "POST", fmt.Sprintf("https://api.igdb.com/v4/%s/webhooks/", endpoint), dataBody.Encode())
if err != nil { if err != nil {
return fmt.Errorf("failed to make request: %s: %w", callbackUrl, err) 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 { if resp.StatusCode() == http.StatusOK {
return nil return nil
} }
return fmt.Errorf("failed to activate webhook: %s: %s", callbackUrl, resp.String())
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
} }

View File

@@ -1,6 +1,7 @@
package endpoint package endpoint
import ( import (
"context"
"fmt" "fmt"
pb "github.com/bestnite/go-igdb/proto" pb "github.com/bestnite/go-igdb/proto"
@@ -8,10 +9,23 @@ import (
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
) )
type WebsiteTypes struct{ BaseEndpoint } type WebsiteTypes struct {
BaseEndpoint[pb.WebsiteType]
}
func (a *WebsiteTypes) Query(query string) ([]*pb.WebsiteType, error) { func NewWebsiteTypes(request RequestFunc) *WebsiteTypes {
resp, err := a.request("https://api.igdb.com/v4/website_types.pb", query) 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 { if err != nil {
return nil, fmt.Errorf("failed to request: %w", err) return nil, fmt.Errorf("failed to request: %w", err)
} }

View File

@@ -1,6 +1,7 @@
package endpoint package endpoint
import ( import (
"context"
"fmt" "fmt"
pb "github.com/bestnite/go-igdb/proto" pb "github.com/bestnite/go-igdb/proto"
@@ -8,10 +9,23 @@ import (
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
) )
type Websites struct{ BaseEndpoint } type Websites struct {
BaseEndpoint[pb.Website]
}
func (a *Websites) Query(query string) ([]*pb.Website, error) { func NewWebsites(request RequestFunc) *Websites {
resp, err := a.request("https://api.igdb.com/v4/websites.pb", query) 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 { if err != nil {
return nil, fmt.Errorf("failed to request: %w", err) return nil, fmt.Errorf("failed to request: %w", err)
} }

1
go.mod
View File

@@ -6,6 +6,7 @@ require (
github.com/PuerkitoBio/goquery v1.10.2 github.com/PuerkitoBio/goquery v1.10.2
github.com/bestnite/go-flaresolverr v0.0.0-20250404141941-4644c2e66727 github.com/bestnite/go-flaresolverr v0.0.0-20250404141941-4644c2e66727
github.com/go-resty/resty/v2 v2.16.5 github.com/go-resty/resty/v2 v2.16.5
golang.org/x/time v0.14.0
google.golang.org/protobuf v1.36.6 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/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-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.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.6.0 h1:eTDhh4ZXt5Qf0augr54TN6suAUudPcawVZeIAPU7D4U= golang.org/x/time v0.14.0 h1:MRx4UaLrDotUKUdCIqzPC48t1Y9hANFKIRpNx+Te8PI=
golang.org/x/time v0.6.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM= 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-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-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20181030000716-a0a13e073c7b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20181030000716-a0a13e073c7b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=

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]; 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 { message AgeRatingContentDescriptionV2Result {
repeated AgeRatingContentDescriptionV2 ageratingcontentdescriptionsv2 = 1; repeated AgeRatingContentDescriptionV2 ageratingcontentdescriptionsv2 = 1;
} }
@@ -220,6 +233,7 @@ message AgeRatingContentDescriptionV2 {
google.protobuf.Timestamp created_at = 4; google.protobuf.Timestamp created_at = 4;
google.protobuf.Timestamp updated_at = 5; google.protobuf.Timestamp updated_at = 5;
string checksum = 6; string checksum = 6;
AgeRatingContentDescriptionType description_type = 7;
} }
message AgeRatingOrganizationResult { message AgeRatingOrganizationResult {
@@ -260,6 +274,20 @@ message Artwork {
string url = 7; string url = 7;
int32 width = 8; int32 width = 8;
string checksum = 9; 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 { message CharacterResult {
@@ -1342,6 +1370,7 @@ message ReleaseDate {
ReleaseDateStatus status = 13; ReleaseDateStatus status = 13;
DateFormat date_format = 14; DateFormat date_format = 14;
ReleaseDateRegion release_region = 15; ReleaseDateRegion release_region = 15;
int32 d = 16;
} }
message ReleaseDateRegionResult { message ReleaseDateRegionResult {

View File

@@ -1,4 +1,4 @@
go install google.golang.org/protobuf/cmd/protoc-gen-go@latest 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 protoc --go_out=. --go_opt=Mproto/igdbapi.proto=/proto ./proto/igdbapi.proto

View File

@@ -1,48 +0,0 @@
package igdb
import (
"sync"
"time"
)
type rateLimiter struct {
mu sync.Mutex
rate int
interval time.Duration
tokens int
lastRefill time.Time
}
func newRateLimiter(rate int) *rateLimiter {
return &rateLimiter{
rate: rate,
interval: time.Second,
tokens: rate,
lastRefill: time.Now(),
}
}
func (r *rateLimiter) wait() {
r.mu.Lock()
defer r.mu.Unlock()
now := time.Now()
elapsed := now.Sub(r.lastRefill)
if elapsed >= r.interval {
r.tokens = r.rate
r.lastRefill = now
}
if r.tokens <= 0 {
waitTime := r.interval - elapsed
r.mu.Unlock()
time.Sleep(waitTime)
r.mu.Lock()
r.tokens = r.rate - 1
r.lastRefill = time.Now()
return
}
r.tokens--
}

View File

@@ -1,358 +1,149 @@
package igdb package igdb
import "github.com/bestnite/go-igdb/endpoint" import (
"github.com/bestnite/go-igdb/endpoint"
)
func registerAllEndpoints(c *Client) { func registerAllEndpoints(c *Client) {
c.AgeRatingCategories = &endpoint.AgeRatingCategories{ c.AgeRatingCategories = endpoint.NewAgeRatingCategories(c.Request)
BaseEndpoint: *endpoint.NewBaseEndpoint(c.Request, endpoint.EPAgeRatingCategories),
} c.AgeRatingContentDescriptions = endpoint.NewAgeRatingContentDescriptions(c.Request)
c.EntityEndpoints[endpoint.EPAgeRatingCategories] = c.AgeRatingCategories
c.AgeRatingContentDescriptionsV2 = endpoint.NewAgeRatingContentDescriptionsV2(c.Request)
c.AgeRatingContentDescriptions = &endpoint.AgeRatingContentDescriptions{
BaseEndpoint: *endpoint.NewBaseEndpoint(c.Request, endpoint.EPAgeRatingContentDescriptions), c.AgeRatingOrganizations = endpoint.NewAgeRatingOrganizations(c.Request)
}
c.EntityEndpoints[endpoint.EPAgeRatingContentDescriptions] = c.AgeRatingContentDescriptions c.AgeRatings = endpoint.NewAgeRatings(c.Request)
c.AgeRatingContentDescriptionsV2 = &endpoint.AgeRatingContentDescriptionsV2{ c.AlternativeNames = endpoint.NewAlternativeNames(c.Request)
BaseEndpoint: *endpoint.NewBaseEndpoint(c.Request, endpoint.EPAgeRatingContentDescriptionsV2),
} c.Artworks = endpoint.NewArtworks(c.Request)
c.EntityEndpoints[endpoint.EPAgeRatingContentDescriptionsV2] = c.AgeRatingContentDescriptionsV2
c.CharacterGenders = endpoint.NewCharacterGenders(c.Request)
c.AgeRatingOrganizations = &endpoint.AgeRatingOrganizations{
BaseEndpoint: *endpoint.NewBaseEndpoint(c.Request, endpoint.EPAgeRatingOrganizations), c.CharacterMugShots = endpoint.NewCharacterMugShots(c.Request)
}
c.EntityEndpoints[endpoint.EPAgeRatingOrganizations] = c.AgeRatingOrganizations c.Characters = endpoint.NewCharacters(c.Request)
c.AgeRatings = &endpoint.AgeRatings{ c.CharacterSpecies = endpoint.NewCharacterSpecies(c.Request)
BaseEndpoint: *endpoint.NewBaseEndpoint(c.Request, endpoint.EPAgeRatings),
} c.CollectionMemberships = endpoint.NewCollectionMemberships(c.Request)
c.EntityEndpoints[endpoint.EPAgeRatings] = c.AgeRatings
c.CollectionMembershipTypes = endpoint.NewCollectionMembershipTypes(c.Request)
c.AlternativeNames = &endpoint.AlternativeNames{
BaseEndpoint: *endpoint.NewBaseEndpoint(c.Request, endpoint.EPAlternativeNames), c.CollectionRelations = endpoint.NewCollectionRelations(c.Request)
}
c.EntityEndpoints[endpoint.EPAlternativeNames] = c.AlternativeNames c.CollectionRelationTypes = endpoint.NewCollectionRelationTypes(c.Request)
c.Artworks = &endpoint.Artworks{ c.Collections = endpoint.NewCollections(c.Request)
BaseEndpoint: *endpoint.NewBaseEndpoint(c.Request, endpoint.EPArtworks),
} c.CollectionTypes = endpoint.NewCollectionTypes(c.Request)
c.EntityEndpoints[endpoint.EPArtworks] = c.Artworks
c.Companies = endpoint.NewCompanies(c.Request)
c.CharacterGenders = &endpoint.CharacterGenders{
BaseEndpoint: *endpoint.NewBaseEndpoint(c.Request, endpoint.EPCharacterGenders), c.CompanyLogos = endpoint.NewCompanyLogos(c.Request)
}
c.EntityEndpoints[endpoint.EPCharacterGenders] = c.CharacterGenders c.CompanyStatuses = endpoint.NewCompanyStatuses(c.Request)
c.CharacterMugShots = &endpoint.CharacterMugShots{ c.CompanyWebsites = endpoint.NewCompanyWebsites(c.Request)
BaseEndpoint: *endpoint.NewBaseEndpoint(c.Request, endpoint.EPCharacterMugShots),
} c.Covers = endpoint.NewCovers(c.Request)
c.EntityEndpoints[endpoint.EPCharacterMugShots] = c.CharacterMugShots
c.DateFormats = endpoint.NewDateFormats(c.Request)
c.Characters = &endpoint.Characters{
BaseEndpoint: *endpoint.NewBaseEndpoint(c.Request, endpoint.EPCharacters), c.EventLogos = endpoint.NewEventLogos(c.Request)
}
c.EntityEndpoints[endpoint.EPCharacters] = c.Characters c.EventNetworks = endpoint.NewEventNetworks(c.Request)
c.CharacterSpecies = &endpoint.CharacterSpecies{ c.Events = endpoint.NewEvents(c.Request)
BaseEndpoint: *endpoint.NewBaseEndpoint(c.Request, endpoint.EPCharacterSpecies),
} c.ExternalGames = endpoint.NewExternalGames(c.Request)
c.EntityEndpoints[endpoint.EPCharacterSpecies] = c.CharacterSpecies
c.ExternalGameSources = endpoint.NewExternalGameSources(c.Request)
c.CollectionMemberships = &endpoint.CollectionMemberships{
BaseEndpoint: *endpoint.NewBaseEndpoint(c.Request, endpoint.EPCollectionMemberships), c.Franchises = endpoint.NewFranchises(c.Request)
}
c.EntityEndpoints[endpoint.EPCollectionMemberships] = c.CollectionMemberships c.GameEngineLogos = endpoint.NewGameEngineLogos(c.Request)
c.CollectionMembershipTypes = &endpoint.CollectionMembershipTypes{ c.GameEngines = endpoint.NewGameEngines(c.Request)
BaseEndpoint: *endpoint.NewBaseEndpoint(c.Request, endpoint.EPCollectionMembershipTypes),
} c.GameLocalizations = endpoint.NewGameLocalizations(c.Request)
c.EntityEndpoints[endpoint.EPCollectionMembershipTypes] = c.CollectionMembershipTypes
c.GameModes = endpoint.NewGameModes(c.Request)
c.CollectionRelations = &endpoint.CollectionRelations{
BaseEndpoint: *endpoint.NewBaseEndpoint(c.Request, endpoint.EPCollectionRelations), c.GameReleaseFormats = endpoint.NewGameReleaseFormats(c.Request)
}
c.EntityEndpoints[endpoint.EPCollectionRelations] = c.CollectionRelations c.Games = endpoint.NewGames(c.Request)
c.CollectionRelationTypes = &endpoint.CollectionRelationTypes{ c.GameStatuses = endpoint.NewGameStatuses(c.Request)
BaseEndpoint: *endpoint.NewBaseEndpoint(c.Request, endpoint.EPCollectionRelationTypes),
} c.GameTimeToBeats = endpoint.NewGameTimeToBeats(c.Request)
c.EntityEndpoints[endpoint.EPCollectionRelationTypes] = c.CollectionRelationTypes
c.GameTypes = endpoint.NewGameTypes(c.Request)
c.Collections = &endpoint.Collections{
BaseEndpoint: *endpoint.NewBaseEndpoint(c.Request, endpoint.EPCollections), c.GameVersionFeatures = endpoint.NewGameVersionFeatures(c.Request)
}
c.EntityEndpoints[endpoint.EPCollections] = c.Collections c.GameVersionFeatureValues = endpoint.NewGameVersionFeatureValues(c.Request)
c.CollectionTypes = &endpoint.CollectionTypes{ c.GameVersions = endpoint.NewGameVersions(c.Request)
BaseEndpoint: *endpoint.NewBaseEndpoint(c.Request, endpoint.EPCollectionTypes),
} c.GameVideos = endpoint.NewGameVideos(c.Request)
c.EntityEndpoints[endpoint.EPCollectionTypes] = c.CollectionTypes
c.Genres = endpoint.NewGenres(c.Request)
c.Companies = &endpoint.Companies{
BaseEndpoint: *endpoint.NewBaseEndpoint(c.Request, endpoint.EPCompanies), c.InvolvedCompanies = endpoint.NewInvolvedCompanies(c.Request)
}
c.EntityEndpoints[endpoint.EPCompanies] = c.Companies c.Keywords = endpoint.NewKeywords(c.Request)
c.CompanyLogos = &endpoint.CompanyLogos{ c.Languages = endpoint.NewLanguages(c.Request)
BaseEndpoint: *endpoint.NewBaseEndpoint(c.Request, endpoint.EPCompanyLogos),
} c.LanguageSupports = endpoint.NewLanguageSupports(c.Request)
c.EntityEndpoints[endpoint.EPCompanyLogos] = c.CompanyLogos
c.LanguageSupportTypes = endpoint.NewLanguageSupportTypes(c.Request)
c.CompanyStatuses = &endpoint.CompanyStatuses{
BaseEndpoint: *endpoint.NewBaseEndpoint(c.Request, endpoint.EPCompanyStatuses), c.MultiplayerModes = endpoint.NewMultiplayerModes(c.Request)
}
c.EntityEndpoints[endpoint.EPCompanyStatuses] = c.CompanyStatuses c.NetworkTypes = endpoint.NewNetworkTypes(c.Request)
c.CompanyWebsites = &endpoint.CompanyWebsites{ c.PlatformFamilies = endpoint.NewPlatformFamilies(c.Request)
BaseEndpoint: *endpoint.NewBaseEndpoint(c.Request, endpoint.EPCompanyWebsites),
} c.PlatformLogos = endpoint.NewPlatformLogos(c.Request)
c.EntityEndpoints[endpoint.EPCompanyWebsites] = c.CompanyWebsites
c.Platforms = endpoint.NewPlatforms(c.Request)
c.Covers = &endpoint.Covers{
BaseEndpoint: *endpoint.NewBaseEndpoint(c.Request, endpoint.EPCovers), c.PlatformTypes = endpoint.NewPlatformTypes(c.Request)
}
c.EntityEndpoints[endpoint.EPCovers] = c.Covers c.PlatformVersionCompanies = endpoint.NewPlatformVersionCompanies(c.Request)
c.DateFormats = &endpoint.DateFormats{ c.PlatformVersionReleaseDates = endpoint.NewPlatformVersionReleaseDates(c.Request)
BaseEndpoint: *endpoint.NewBaseEndpoint(c.Request, endpoint.EPDateFormats),
} c.PlatformVersions = endpoint.NewPlatformVersions(c.Request)
c.EntityEndpoints[endpoint.EPDateFormats] = c.DateFormats
c.PlatformWebsites = endpoint.NewPlatformWebsites(c.Request)
c.EventLogos = &endpoint.EventLogos{
BaseEndpoint: *endpoint.NewBaseEndpoint(c.Request, endpoint.EPEventLogos), c.PlayerPerspectives = endpoint.NewPlayerPerspectives(c.Request)
}
c.EntityEndpoints[endpoint.EPEventLogos] = c.EventLogos c.PopularityPrimitives = endpoint.NewPopularityPrimitives(c.Request)
c.EventNetworks = &endpoint.EventNetworks{ c.PopularityTypes = endpoint.NewPopularityTypes(c.Request)
BaseEndpoint: *endpoint.NewBaseEndpoint(c.Request, endpoint.EPEventNetworks),
} c.Regions = endpoint.NewRegions(c.Request)
c.EntityEndpoints[endpoint.EPEventNetworks] = c.EventNetworks
c.ReleaseDateRegions = endpoint.NewReleaseDateRegions(c.Request)
c.Events = &endpoint.Events{
BaseEndpoint: *endpoint.NewBaseEndpoint(c.Request, endpoint.EPEvents), c.ReleaseDates = endpoint.NewReleaseDates(c.Request)
}
c.EntityEndpoints[endpoint.EPEvents] = c.Events c.ReleaseDateStatuses = endpoint.NewReleaseDateStatuses(c.Request)
c.ExternalGames = &endpoint.ExternalGames{ c.Screenshots = endpoint.NewScreenshots(c.Request)
BaseEndpoint: *endpoint.NewBaseEndpoint(c.Request, endpoint.EPExternalGames),
} c.Themes = endpoint.NewThemes(c.Request)
c.EntityEndpoints[endpoint.EPExternalGames] = c.ExternalGames
c.Websites = endpoint.NewWebsites(c.Request)
c.ExternalGameSources = &endpoint.ExternalGameSources{
BaseEndpoint: *endpoint.NewBaseEndpoint(c.Request, endpoint.EPExternalGameSources), c.WebsiteTypes = endpoint.NewWebsiteTypes(c.Request)
}
c.EntityEndpoints[endpoint.EPExternalGameSources] = c.ExternalGameSources c.Webhooks = endpoint.NewWebhooks(c.Request)
c.Franchises = &endpoint.Franchises{ c.Search = endpoint.NewSearch(c.Request)
BaseEndpoint: *endpoint.NewBaseEndpoint(c.Request, endpoint.EPFranchises),
}
c.EntityEndpoints[endpoint.EPFranchises] = c.Franchises
c.GameEngineLogos = &endpoint.GameEngineLogos{
BaseEndpoint: *endpoint.NewBaseEndpoint(c.Request, endpoint.EPGameEngineLogos),
}
c.EntityEndpoints[endpoint.EPGameEngineLogos] = c.GameEngineLogos
c.GameEngines = &endpoint.GameEngines{
BaseEndpoint: *endpoint.NewBaseEndpoint(c.Request, endpoint.EPGameEngines),
}
c.EntityEndpoints[endpoint.EPGameEngines] = c.GameEngines
c.GameLocalizations = &endpoint.GameLocalizations{
BaseEndpoint: *endpoint.NewBaseEndpoint(c.Request, endpoint.EPGameLocalizations),
}
c.EntityEndpoints[endpoint.EPGameLocalizations] = c.GameLocalizations
c.GameModes = &endpoint.GameModes{
BaseEndpoint: *endpoint.NewBaseEndpoint(c.Request, endpoint.EPGameModes),
}
c.EntityEndpoints[endpoint.EPGameModes] = c.GameModes
c.GameReleaseFormats = &endpoint.GameReleaseFormats{
BaseEndpoint: *endpoint.NewBaseEndpoint(c.Request, endpoint.EPGameReleaseFormats),
}
c.EntityEndpoints[endpoint.EPGameReleaseFormats] = c.GameReleaseFormats
c.Games = &endpoint.Games{
BaseEndpoint: *endpoint.NewBaseEndpoint(c.Request, endpoint.EPGames),
}
c.EntityEndpoints[endpoint.EPGames] = c.Games
c.GameStatuses = &endpoint.GameStatuses{
BaseEndpoint: *endpoint.NewBaseEndpoint(c.Request, endpoint.EPGameStatuses),
}
c.EntityEndpoints[endpoint.EPGameStatuses] = c.GameStatuses
c.GameTimeToBeats = &endpoint.GameTimeToBeats{
BaseEndpoint: *endpoint.NewBaseEndpoint(c.Request, endpoint.EPGameTimeToBeats),
}
c.EntityEndpoints[endpoint.EPGameTimeToBeats] = c.GameTimeToBeats
c.GameTypes = &endpoint.GameTypes{
BaseEndpoint: *endpoint.NewBaseEndpoint(c.Request, endpoint.EPGameTypes),
}
c.EntityEndpoints[endpoint.EPGameTypes] = c.GameTypes
c.GameVersionFeatures = &endpoint.GameVersionFeatures{
BaseEndpoint: *endpoint.NewBaseEndpoint(c.Request, endpoint.EPGameVersionFeatures),
}
c.EntityEndpoints[endpoint.EPGameVersionFeatures] = c.GameVersionFeatures
c.GameVersionFeatureValues = &endpoint.GameVersionFeatureValues{
BaseEndpoint: *endpoint.NewBaseEndpoint(c.Request, endpoint.EPGameVersionFeatureValues),
}
c.EntityEndpoints[endpoint.EPGameVersionFeatureValues] = c.GameVersionFeatureValues
c.GameVersions = &endpoint.GameVersions{
BaseEndpoint: *endpoint.NewBaseEndpoint(c.Request, endpoint.EPGameVersions),
}
c.EntityEndpoints[endpoint.EPGameVersions] = c.GameVersions
c.GameVideos = &endpoint.GameVideos{
BaseEndpoint: *endpoint.NewBaseEndpoint(c.Request, endpoint.EPGameVideos),
}
c.EntityEndpoints[endpoint.EPGameVideos] = c.GameVideos
c.Genres = &endpoint.Genres{
BaseEndpoint: *endpoint.NewBaseEndpoint(c.Request, endpoint.EPGenres),
}
c.EntityEndpoints[endpoint.EPGenres] = c.Genres
c.InvolvedCompanies = &endpoint.InvolvedCompanies{
BaseEndpoint: *endpoint.NewBaseEndpoint(c.Request, endpoint.EPInvolvedCompanies),
}
c.EntityEndpoints[endpoint.EPInvolvedCompanies] = c.InvolvedCompanies
c.Keywords = &endpoint.Keywords{
BaseEndpoint: *endpoint.NewBaseEndpoint(c.Request, endpoint.EPKeywords),
}
c.EntityEndpoints[endpoint.EPKeywords] = c.Keywords
c.Languages = &endpoint.Languages{
BaseEndpoint: *endpoint.NewBaseEndpoint(c.Request, endpoint.EPLanguages),
}
c.EntityEndpoints[endpoint.EPLanguages] = c.Languages
c.LanguageSupports = &endpoint.LanguageSupports{
BaseEndpoint: *endpoint.NewBaseEndpoint(c.Request, endpoint.EPLanguageSupports),
}
c.EntityEndpoints[endpoint.EPLanguageSupports] = c.LanguageSupports
c.LanguageSupportTypes = &endpoint.LanguageSupportTypes{
BaseEndpoint: *endpoint.NewBaseEndpoint(c.Request, endpoint.EPLanguageSupportTypes),
}
c.EntityEndpoints[endpoint.EPLanguageSupportTypes] = c.LanguageSupportTypes
c.MultiplayerModes = &endpoint.MultiplayerModes{
BaseEndpoint: *endpoint.NewBaseEndpoint(c.Request, endpoint.EPMultiplayerModes),
}
c.EntityEndpoints[endpoint.EPMultiplayerModes] = c.MultiplayerModes
c.NetworkTypes = &endpoint.NetworkTypes{
BaseEndpoint: *endpoint.NewBaseEndpoint(c.Request, endpoint.EPNetworkTypes),
}
c.EntityEndpoints[endpoint.EPNetworkTypes] = c.NetworkTypes
c.PlatformFamilies = &endpoint.PlatformFamilies{
BaseEndpoint: *endpoint.NewBaseEndpoint(c.Request, endpoint.EPPlatformFamilies),
}
c.EntityEndpoints[endpoint.EPPlatformFamilies] = c.PlatformFamilies
c.PlatformLogos = &endpoint.PlatformLogos{
BaseEndpoint: *endpoint.NewBaseEndpoint(c.Request, endpoint.EPPlatformLogos),
}
c.EntityEndpoints[endpoint.EPPlatformLogos] = c.PlatformLogos
c.Platforms = &endpoint.Platforms{
BaseEndpoint: *endpoint.NewBaseEndpoint(c.Request, endpoint.EPPlatforms),
}
c.EntityEndpoints[endpoint.EPPlatforms] = c.Platforms
c.PlatformTypes = &endpoint.PlatformTypes{
BaseEndpoint: *endpoint.NewBaseEndpoint(c.Request, endpoint.EPPlatformTypes),
}
c.EntityEndpoints[endpoint.EPPlatformTypes] = c.PlatformTypes
c.PlatformVersionCompanies = &endpoint.PlatformVersionCompanies{
BaseEndpoint: *endpoint.NewBaseEndpoint(c.Request, endpoint.EPPlatformVersionCompanies),
}
c.EntityEndpoints[endpoint.EPPlatformVersionCompanies] = c.PlatformVersionCompanies
c.PlatformVersionReleaseDates = &endpoint.PlatformVersionReleaseDates{
BaseEndpoint: *endpoint.NewBaseEndpoint(c.Request, endpoint.EPPlatformVersionReleaseDates),
}
c.EntityEndpoints[endpoint.EPPlatformVersionReleaseDates] = c.PlatformVersionReleaseDates
c.PlatformVersions = &endpoint.PlatformVersions{
BaseEndpoint: *endpoint.NewBaseEndpoint(c.Request, endpoint.EPPlatformVersions),
}
c.EntityEndpoints[endpoint.EPPlatformVersions] = c.PlatformVersions
c.PlatformWebsites = &endpoint.PlatformWebsites{
BaseEndpoint: *endpoint.NewBaseEndpoint(c.Request, endpoint.EPPlatformWebsites),
}
c.EntityEndpoints[endpoint.EPPlatformWebsites] = c.PlatformWebsites
c.PlayerPerspectives = &endpoint.PlayerPerspectives{
BaseEndpoint: *endpoint.NewBaseEndpoint(c.Request, endpoint.EPPlayerPerspectives),
}
c.EntityEndpoints[endpoint.EPPlayerPerspectives] = c.PlayerPerspectives
c.PopularityPrimitives = &endpoint.PopularityPrimitives{
BaseEndpoint: *endpoint.NewBaseEndpoint(c.Request, endpoint.EPPopularityPrimitives),
}
c.EntityEndpoints[endpoint.EPPopularityPrimitives] = c.PopularityPrimitives
c.PopularityTypes = &endpoint.PopularityTypes{
BaseEndpoint: *endpoint.NewBaseEndpoint(c.Request, endpoint.EPPopularityTypes),
}
c.EntityEndpoints[endpoint.EPPopularityTypes] = c.PopularityTypes
c.Regions = &endpoint.Regions{
BaseEndpoint: *endpoint.NewBaseEndpoint(c.Request, endpoint.EPRegions),
}
c.EntityEndpoints[endpoint.EPRegions] = c.Regions
c.ReleaseDateRegions = &endpoint.ReleaseDateRegions{
BaseEndpoint: *endpoint.NewBaseEndpoint(c.Request, endpoint.EPReleaseDateRegions),
}
c.EntityEndpoints[endpoint.EPReleaseDateRegions] = c.ReleaseDateRegions
c.ReleaseDates = &endpoint.ReleaseDates{
BaseEndpoint: *endpoint.NewBaseEndpoint(c.Request, endpoint.EPReleaseDates),
}
c.EntityEndpoints[endpoint.EPReleaseDates] = c.ReleaseDates
c.ReleaseDateStatuses = &endpoint.ReleaseDateStatuses{
BaseEndpoint: *endpoint.NewBaseEndpoint(c.Request, endpoint.EPReleaseDateStatuses),
}
c.EntityEndpoints[endpoint.EPReleaseDateStatuses] = c.ReleaseDateStatuses
c.Screenshots = &endpoint.Screenshots{
BaseEndpoint: *endpoint.NewBaseEndpoint(c.Request, endpoint.EPScreenshots),
}
c.EntityEndpoints[endpoint.EPScreenshots] = c.Screenshots
c.Themes = &endpoint.Themes{
BaseEndpoint: *endpoint.NewBaseEndpoint(c.Request, endpoint.EPThemes),
}
c.EntityEndpoints[endpoint.EPThemes] = c.Themes
c.Websites = &endpoint.Websites{
BaseEndpoint: *endpoint.NewBaseEndpoint(c.Request, endpoint.EPWebsites),
}
c.EntityEndpoints[endpoint.EPWebsites] = c.Websites
c.WebsiteTypes = &endpoint.WebsiteTypes{
BaseEndpoint: *endpoint.NewBaseEndpoint(c.Request, endpoint.EPWebsiteTypes),
}
c.EntityEndpoints[endpoint.EPWebsiteTypes] = c.WebsiteTypes
c.Webhooks = &endpoint.Webhooks{
BaseEndpoint: *endpoint.NewBaseEndpoint(c.Request, endpoint.EPWebhooks),
}
c.Search = &endpoint.Search{
BaseEndpoint: *endpoint.NewBaseEndpoint(c.Request, endpoint.EPSearch),
}
} }

View File

@@ -7,23 +7,19 @@ import (
"github.com/go-resty/resty/v2" "github.com/go-resty/resty/v2"
) )
var client *resty.Client type SilentLogger struct{}
func init() { func (s SilentLogger) Errorf(string, ...any) {}
client = resty.New() func (s SilentLogger) Warnf(string, ...any) {}
client.SetRetryCount(3).SetRetryWaitTime(3 * time.Second).AddRetryCondition( 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 { 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,6 +1,7 @@
package igdb package igdb
import ( import (
"context"
"encoding/json" "encoding/json"
"fmt" "fmt"
"net/url" "net/url"
@@ -14,18 +15,18 @@ type twitchToken struct {
expires time.Time expires time.Time
} }
func NewTwitchToken(clientID, clientSecret string) *twitchToken { func newTwitchToken(clientID, clientSecret string) *twitchToken {
return &twitchToken{ return &twitchToken{
clientID: clientID, clientID: clientID,
clientSecret: clientSecret, 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) { if t.token != "" && time.Now().Before(t.expires) {
return t.token, nil return t.token, nil
} }
token, expires, err := t.loginTwitch() token, expires, err := t.LoginTwitch(ctx)
if err != nil { if err != nil {
return "", fmt.Errorf("failed to login twitch: %w", err) return "", fmt.Errorf("failed to login twitch: %w", err)
} }
@@ -34,7 +35,7 @@ func (t *twitchToken) getToken() (string, error) {
return token, nil return token, nil
} }
func (t *twitchToken) loginTwitch() (string, time.Duration, error) { func (t *twitchToken) LoginTwitch(ctx context.Context) (string, time.Duration, error) {
baseURL, _ := url.Parse("https://id.twitch.tv/oauth2/token") baseURL, _ := url.Parse("https://id.twitch.tv/oauth2/token")
params := url.Values{} params := url.Values{}
params.Add("client_id", t.clientID) params.Add("client_id", t.clientID)
@@ -42,7 +43,7 @@ func (t *twitchToken) loginTwitch() (string, time.Duration, error) {
params.Add("grant_type", "client_credentials") params.Add("grant_type", "client_credentials")
baseURL.RawQuery = params.Encode() 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 { if err != nil {
return "", 0, fmt.Errorf("failed to make request: %s: %w", baseURL.String(), err) return "", 0, fmt.Errorf("failed to make request: %s: %w", baseURL.String(), err)
} }