Skip to content

config

import "github.com/wnjoon/go-yfinance/pkg/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:

config.Reset()

Index

Constants

Default configuration values

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

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

func Get() *Config

Get returns the global configuration instance.

func NewDefault

func NewDefault() *Config

NewDefault creates a new Config with default values.

func (*Config) Clone

func (c *Config) Clone() *Config

Clone creates a copy of the configuration.

func (*Config) DisableCache

func (c *Config) DisableCache() *Config

DisableCache disables response caching.

func (*Config) EnableCache

func (c *Config) EnableCache(ttl time.Duration) *Config

EnableCache enables response caching.

func (*Config) GetJA3

func (c *Config) GetJA3() string

GetJA3 returns the JA3 fingerprint.

func (*Config) GetLocale

func (c *Config) GetLocale() (lang, region string)

GetLocale returns the configured Yahoo Finance locale.

func (*Config) GetProxyURL

func (c *Config) GetProxyURL() string

GetProxyURL returns the proxy URL.

func (*Config) GetTimeout

func (c *Config) GetTimeout() time.Duration

GetTimeout returns the timeout value.

func (*Config) GetUserAgent

func (c *Config) GetUserAgent() string

GetUserAgent returns the User-Agent string.

func (*Config) IsCacheEnabled

func (c *Config) IsCacheEnabled() bool

IsCacheEnabled returns whether caching is enabled.

func (*Config) IsDebug

func (c *Config) IsDebug() bool

IsDebug returns whether debug mode is enabled.

func (*Config) SetDebug

func (c *Config) SetDebug(debug bool) *Config

SetDebug enables or disables debug mode.

func (*Config) SetJA3

func (c *Config) SetJA3(ja3 string) *Config

SetJA3 sets the JA3 TLS fingerprint.

func (*Config) SetLocale

func (c *Config) SetLocale(lang, region string) *Config

SetLocale sets the Yahoo Finance locale for endpoints that support localized fields.

func (*Config) SetMaxConcurrent

func (c *Config) SetMaxConcurrent(n int) *Config

SetMaxConcurrent sets the maximum concurrent requests.

func (*Config) SetMaxRetries

func (c *Config) SetMaxRetries(n int) *Config

SetMaxRetries sets the maximum number of retries.

func (*Config) SetProxy

func (c *Config) SetProxy(proxyURL string) *Config

SetProxy sets the proxy URL.

func (*Config) SetRetryDelay

func (c *Config) SetRetryDelay(d time.Duration) *Config

SetRetryDelay sets the delay between retries.

func (*Config) SetTimeout

func (c *Config) SetTimeout(d time.Duration) *Config

SetTimeout sets the HTTP request timeout.

func (*Config) SetUserAgent

func (c *Config) SetUserAgent(ua string) *Config

SetUserAgent sets the User-Agent string.