go-igdb/endpoint/age_rating_content_descriptions_v2.go
2025-04-09 17:10:53 +10:00

43 lines
1.1 KiB
Go

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