config
Package config provides configuration management for go-yfinance.
Overview
The config package provides a centralized way to configure go-yfinance behavior. It supports both global configuration via Get and per-instance configuration via NewDefault.
Global Configuration
import "github.com/wnjoon/go-yfinance/pkg/config"
// Get global config and modify settings
config.Get().
SetTimeout(60 * time.Second).
SetProxy("http://proxy:8080").
SetDebug(true)
Available Settings
HTTP Client:
- Timeout: Request timeout duration
- UserAgent: Custom User-Agent string
- JA3: TLS fingerprint for spoofing
- ProxyURL: HTTP/HTTPS proxy URL
Rate Limiting:
- MaxRetries: Maximum retry attempts
- RetryDelay: Delay between retries
- MaxConcurrent: Maximum concurrent requests
Caching:
- CacheEnabled: Enable/disable response caching
- CacheTTL: Cache time-to-live duration
Debug:
- Debug: Enable debug logging
Thread Safety
All Config methods are safe for concurrent use.
Reset
Use Reset to restore global configuration to defaults:
Index
- Constants
- func Reset()
- type Config
- func Get() *Config
- func NewDefault() *Config
- func (c *Config) Clone() *Config
- func (c *Config) DisableCache() *Config
- func (c *Config) EnableCache(ttl time.Duration) *Config
- func (c *Config) GetJA3() string
- func (c *Config) GetLocale() (lang, region string)
- func (c *Config) GetProxyURL() string
- func (c *Config) GetTimeout() time.Duration
- func (c *Config) GetUserAgent() string
- func (c *Config) IsCacheEnabled() bool
- func (c *Config) IsDebug() bool
- func (c *Config) SetDebug(debug bool) *Config
- func (c *Config) SetJA3(ja3 string) *Config
- func (c *Config) SetLocale(lang, region string) *Config
- func (c *Config) SetMaxConcurrent(n int) *Config
- func (c *Config) SetMaxRetries(n int) *Config
- func (c *Config) SetProxy(proxyURL string) *Config
- func (c *Config) SetRetryDelay(d time.Duration) *Config
- func (c *Config) SetTimeout(d time.Duration) *Config
- func (c *Config) SetUserAgent(ua string) *Config
Constants
const (
DefaultTimeout = 30 * time.Second
DefaultMaxRetries = 3
DefaultRetryDelay = 1 * time.Second
DefaultMaxConcurrent = 10
DefaultCacheTTL = 5 * time.Minute
DefaultLang = "en-US"
DefaultRegion = "US"
)
Default JA3 fingerprint (Chrome)
const DefaultJA3 = "771,4865-4866-4867-49195-49199-49196-49200-52393-52392-49171-49172-156-157-47-53,0-23-65281-10-11-35-16-5-13-18-51-45-43-27-17513,29-23-24,0"
func Reset
Reset resets the global configuration to defaults.
type Config
Config holds the global configuration for go-yfinance.
type Config struct {
// HTTP Client settings
Timeout time.Duration
UserAgent string
JA3 string
// Proxy settings
ProxyURL string
// Rate limiting
MaxRetries int
RetryDelay time.Duration
MaxConcurrent int
// Cache settings
CacheEnabled bool
CacheTTL time.Duration
// Locale settings for Yahoo v7/v10 endpoints
Lang string
Region string
// Debug settings
Debug bool
// contains filtered or unexported fields
}
func Get
Get returns the global configuration instance.
func NewDefault
NewDefault creates a new Config with default values.
func (*Config) Clone
Clone creates a copy of the configuration.
func (*Config) DisableCache
DisableCache disables response caching.
func (*Config) EnableCache
EnableCache enables response caching.
func (*Config) GetJA3
GetJA3 returns the JA3 fingerprint.
func (*Config) GetLocale
GetLocale returns the configured Yahoo Finance locale.
func (*Config) GetProxyURL
GetProxyURL returns the proxy URL.
func (*Config) GetTimeout
GetTimeout returns the timeout value.
func (*Config) GetUserAgent
GetUserAgent returns the User-Agent string.
func (*Config) IsCacheEnabled
IsCacheEnabled returns whether caching is enabled.
func (*Config) IsDebug
IsDebug returns whether debug mode is enabled.
func (*Config) SetDebug
SetDebug enables or disables debug mode.
func (*Config) SetJA3
SetJA3 sets the JA3 TLS fingerprint.
func (*Config) SetLocale
SetLocale sets the Yahoo Finance locale for endpoints that support localized fields.
func (*Config) SetMaxConcurrent
SetMaxConcurrent sets the maximum concurrent requests.
func (*Config) SetMaxRetries
SetMaxRetries sets the maximum number of retries.
func (*Config) SetProxy
SetProxy sets the proxy URL.
func (*Config) SetRetryDelay
SetRetryDelay sets the delay between retries.
func (*Config) SetTimeout
SetTimeout sets the HTTP request timeout.
func (*Config) SetUserAgent
SetUserAgent sets the User-Agent string.