config

package
v0.12.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 27, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

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

func New(opts ...Option) (*Config, error)

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

func (c *Config) ExtraValue(key string) (any, bool)

ExtraValue retrieves a provider-specific configuration value.

func (*Config) HTTPClient

func (c *Config) HTTPClient() *http.Client

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

func (c *Config) ResolveAPIKey(envVar string) string

ResolveAPIKey returns the API key from config if set, otherwise falls back to the specified environment variable.

func (*Config) ResolveBaseURL

func (c *Config) ResolveBaseURL(envVar, defaultVal string) (string, error)

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

func (c *Config) ResolveEnv(envVar string) string

ResolveEnv returns the value of the specified environment variable, trimming whitespace. Returns empty string if the variable is not set or empty.

type Option

type Option func(*Config) error

Option is a function that modifies the Config.

func WithAPIKey

func WithAPIKey(key string) Option

WithAPIKey sets the API key. Whitespace is automatically trimmed.

func WithBaseURL

func WithBaseURL(baseURL string) Option

WithBaseURL sets the base URL.

func WithExtra

func WithExtra(key string, value any) Option

WithExtra sets extra provider-specific configuration. Whitespace is automatically trimmed from the key.

func WithHTTPClient

func WithHTTPClient(client *http.Client) Option

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.

func WithTimeout

func WithTimeout(d time.Duration) Option

WithTimeout sets the request timeout.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL