feat: add producer data types and caching

This commit is contained in:
2026-05-25 17:59:11 +02:00
parent f4a9453514
commit e54d6b8142
3 changed files with 158 additions and 1 deletions

View File

@@ -1,6 +1,9 @@
package jikan
import ()
import (
"context"
"fmt"
)
type ProducerResponse struct {
Data struct {
@@ -24,3 +27,18 @@ type ProducerResponse struct {
} `json:"external"`
} `json:"data"`
}
func (c *Client) GetProducerByID(ctx context.Context, id int) (ProducerResponse, error) {
if id <= 0 {
return ProducerResponse{}, fmt.Errorf("invalid producer id")
}
cacheKey := fmt.Sprintf("producer:%d", id)
reqURL := fmt.Sprintf("%s/producers/%d", c.baseURL, id)
var result ProducerResponse
if err := c.getWithCache(ctx, cacheKey, producerCacheTTL, reqURL, &result); err != nil {
return ProducerResponse{}, err
}
return result, nil
}