feat: init client
This commit is contained in:
40
client/cards.go
Normal file
40
client/cards.go
Normal file
@@ -0,0 +1,40 @@
|
||||
package client
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
|
||||
"github.com/kratisto/tcgdex-golang/models"
|
||||
)
|
||||
|
||||
// GetCard retrieves a specific card by its ID.
|
||||
// This function is used to get detailed information about a specific card.
|
||||
func (s *tcgDexClient) GetCard(ctx context.Context, id string) (*models.Card, error) {
|
||||
request, err := http.NewRequestWithContext(ctx, http.MethodGet, s.baseURL+"/cards/"+id, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
card, err := doRequest[*models.Card](s.httpClient, request)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return card, nil
|
||||
}
|
||||
|
||||
// Cards retrieves all cards.
|
||||
// This function returns a list of all cards available in the Pokémon TCG database.
|
||||
func (s *tcgDexClient) Cards(ctx context.Context) ([]*models.Card, error) {
|
||||
request, err := http.NewRequestWithContext(ctx, http.MethodGet, s.baseURL+"/cards", nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
cards, err := doRequest[[]*models.Card](s.httpClient, request)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return cards, nil
|
||||
}
|
||||
Reference in New Issue
Block a user