api: pass request context to jikan
This commit is contained in:
@@ -1,20 +1,21 @@
|
||||
package jikan
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
func (c *Client) GetAnimeByID(id int) (Anime, error) {
|
||||
func (c *Client) GetAnimeByID(ctx context.Context, id int) (Anime, error) {
|
||||
cacheKey := fmt.Sprintf("anime:%d", id)
|
||||
var cached Anime
|
||||
if c.getCache(cacheKey, &cached) {
|
||||
if c.getCache(ctx, cacheKey, &cached) {
|
||||
return cached, nil
|
||||
}
|
||||
|
||||
var result AnimeResponse
|
||||
reqURL := fmt.Sprintf("%s/anime/%d/full", c.baseURL, id)
|
||||
if err := c.fetchWithRetry(reqURL, &result); err != nil {
|
||||
if err := c.fetchWithRetry(ctx, reqURL, &result); err != nil {
|
||||
return Anime{}, err
|
||||
}
|
||||
|
||||
@@ -23,6 +24,6 @@ func (c *Client) GetAnimeByID(id int) (Anime, error) {
|
||||
ttl = time.Hour * 24 * 30
|
||||
}
|
||||
|
||||
c.setCache(cacheKey, result.Data, ttl)
|
||||
c.setCache(ctx, cacheKey, result.Data, ttl)
|
||||
return result.Data, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user