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