Files
go-igdb/endpoint/age_rating_content_descriptions.go
2025-10-28 22:36:26 +11:00

40 lines
1.0 KiB
Go

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