small fix, don't worry about it

This commit is contained in:
Tomas Dvorak
2026-04-10 12:06:24 +02:00
commit 5c500a72b0
243 changed files with 44176 additions and 0 deletions
@@ -0,0 +1,55 @@
package tmdb
import (
"context"
"errors"
"net/http"
"time"
"github.com/tdvorak/seen/backend/internal/config"
)
var ErrTMDBAPIKeyMissing = errors.New("tmdb api key missing")
type Client struct {
apiKey string
baseURL string
httpClient *http.Client
}
func NewClient(cfg config.TMDBConfig) *Client {
return &Client{
apiKey: cfg.APIKey,
baseURL: cfg.BaseURL,
httpClient: &http.Client{
Timeout: 10 * time.Second,
},
}
}
func (c *Client) Validate(ctx context.Context) error {
if c.apiKey == "" {
return ErrTMDBAPIKeyMissing
}
request, err := http.NewRequestWithContext(ctx, http.MethodGet, c.baseURL+"/configuration", nil)
if err != nil {
return err
}
query := request.URL.Query()
query.Set("api_key", c.apiKey)
request.URL.RawQuery = query.Encode()
response, err := c.httpClient.Do(request)
if err != nil {
return err
}
defer response.Body.Close()
if response.StatusCode >= 400 {
return errors.New("tmdb validation request failed")
}
return nil
}