mirror of
https://github.com/bestnite/go-igdb.git
synced 2025-04-19 22:25:54 +08:00
32 lines
770 B
Go
32 lines
770 B
Go
package endpoint
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
pb "github.com/bestnite/go-igdb/proto"
|
|
|
|
"google.golang.org/protobuf/proto"
|
|
)
|
|
|
|
type AgeRatingContentDescriptions struct {
|
|
BaseEndpoint
|
|
}
|
|
|
|
func (a *AgeRatingContentDescriptions) Query(query string) ([]*pb.AgeRatingContentDescription, error) {
|
|
resp, err := a.request("https://api.igdb.com/v4/age_rating_content_descriptions.pb", query)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("failed to request: %w", err)
|
|
}
|
|
|
|
data := pb.AgeRatingContentDescriptionResult{}
|
|
if err = proto.Unmarshal(resp.Body(), &data); err != nil {
|
|
return nil, fmt.Errorf("failed to unmarshal: %w", err)
|
|
}
|
|
|
|
if len(data.Ageratingcontentdescriptions) == 0 {
|
|
return nil, fmt.Errorf("no results: %s", query)
|
|
}
|
|
|
|
return data.Ageratingcontentdescriptions, nil
|
|
}
|