Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
// APIKey is the API key for authentication.
APIKey string
// BaseURL is the base URL for the API. If empty, the provider's default is used.
BaseURL string
// Extra holds provider-specific configuration options.
Extra map[string]any
// Timeout is the request timeout. If zero, a default timeout is used.
Timeout time.Duration
// contains filtered or unexported fields
}
Config holds the configuration for a provider.
func New ¶
New creates a Config with the given options applied. Note: HTTPClient is not created here by default; it is lazily created via the HTTPClient() method using the configured Timeout when first accessed.
func (*Config) ExtraValue ¶
ExtraValue retrieves a provider-specific configuration value.
func (*Config) HTTPClient ¶
HTTPClient returns the configured HTTP client, or lazily creates one using the configured Timeout if no custom client was provided via WithHTTPClient. The lazily-created client is cached and reused on subsequent calls.
Note: If a custom client was provided via WithHTTPClient, that pointer is returned.
func (*Config) ResolveAPIKey ¶
ResolveAPIKey returns the API key from config if set, otherwise falls back to the specified environment variable.
func (*Config) ResolveBaseURL ¶
ResolveBaseURL resolves the base URL from config, environment variable, or default value. It validates that the resolved URL has a scheme and host.
func (*Config) ResolveEnv ¶
ResolveEnv returns the value of the specified environment variable, trimming whitespace. Returns empty string if the variable is not set or empty.
type Option ¶
Option is a function that modifies the Config.
func WithAPIKey ¶
WithAPIKey sets the API key. Whitespace is automatically trimmed.
func WithExtra ¶
WithExtra sets extra provider-specific configuration. Whitespace is automatically trimmed from the key.
func WithHTTPClient ¶
WithHTTPClient sets a custom HTTP client. When a custom client is provided, the Timeout field is ignored for HTTP requests since the custom client manages its own timeout configuration. If both WithHTTPClient and WithTimeout are used, the custom client takes precedence.