fix: send account-manager token as x-api-key

This commit is contained in:
2026-04-03 19:12:34 +00:00
parent e2177521e0
commit ad0e123666
2 changed files with 16 additions and 2 deletions

View File

@@ -14,6 +14,7 @@ import (
type Client struct {
BaseURL string
Token string
APIKey string
HTTPClient *http.Client
}
@@ -28,6 +29,17 @@ func New(baseURL, token string) *Client {
}
}
// NewWithAPIKey creates a Client that authenticates using X-API-Key.
func NewWithAPIKey(baseURL, apiKey string) *Client {
return &Client{
BaseURL: strings.TrimRight(baseURL, "/"),
APIKey: apiKey,
HTTPClient: &http.Client{
Timeout: 30 * time.Second,
},
}
}
// RequestError represents a non-2xx HTTP response.
type RequestError struct {
StatusCode int
@@ -45,7 +57,9 @@ func (c *Client) Do(method, path string, body io.Reader) ([]byte, error) {
if err != nil {
return nil, fmt.Errorf("cannot create request: %w", err)
}
if c.Token != "" {
if c.APIKey != "" {
req.Header.Set("X-API-Key", c.APIKey)
} else if c.Token != "" {
req.Header.Set("Authorization", "Bearer "+c.Token)
}
if body != nil {