config

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type SteamConfig

type SteamConfig struct {
	// 基本配置 | Basic configuration
	APIKey         string            `json:"api_key" env:"STEAM_API_KEY"`                   // Steam API 密钥
	ProxyURL       string            `json:"proxy_url" env:"STEAM_PROXY_URL"`               // 代理地址(中国区必填)
	ProxyUser      string            `json:"proxy_user" env:"STEAM_PROXY_USER"`             // 代理用户名
	ProxyPass      string            `json:"proxy_pass" env:"STEAM_PROXY_PASS"`             // 代理密码
	ProxyPool      []string          `json:"proxy_pool" env:"STEAM_PROXY_POOL"`             // 代理IP池
	ProxyStrategy  string            `json:"proxy_strategy" env:"STEAM_PROXY_STRATEGY"`     // 代理选择策略
	Timeout        time.Duration     `json:"timeout" env:"STEAM_TIMEOUT"`                   // 请求超时时间(秒)
	RetryTimes     int               `json:"retry_times" env:"STEAM_RETRY_TIMES"`           // 重试次数
	RateLimitQPS   float64           `json:"rate_limit_qps" env:"STEAM_RATE_LIMIT_QPS"`     // 限速QPS
	RateLimitBurst int               `json:"rate_limit_burst" env:"STEAM_RATE_LIMIT_BURST"` // 突发QPS上限
	Headers        map[string]string `json:"headers"`                                       // 请求头

	// 运行时 | Runtime
	Transport *http.Transport `json:"-"` // 运行时构建的 Transport | Runtime-built Transport

	// 爬虫配置 | Crawler configuration
	CrawlerUserAgent   string        `json:"crawler_user_agent" env:"STEAM_CRAWLER_UA"`           // 爬虫user-agent
	CrawlerAsync       bool          `json:"crawler_async" env:"STEAM_CRAWLER_ASYNC"`             // 异步爬虫
	CrawlerMaxDepth    int           `json:"crawler_max_depth" env:"STEAM_CRAWLER_MAX_DEPTH"`     // 爬取深度
	CrawlerConcurrency int           `json:"crawler_concurrency" env:"STEAM_CRAWLER_CONCURRENCY"` // 并发数
	CrawlerDelay       time.Duration `json:"crawler_delay" env:"STEAM_CRAWLER_DELAY"`             // 每次请求延迟(毫秒)
	CrawlerQPS         float64       `json:"crawler_qps" env:"STEAM_CRAWLER_QPS"`                 // 爬虫限速QPS
	CrawlerBurst       int           `json:"crawler_burst" env:"STEAM_CRAWLER_BURST"`             // 爬虫突发QPS上限
	CrawlerCookie      string        `json:"crawler_cookie" env:"STEAM_CRAWLER_COOKIE"`           // Steam 登录 Cookie
	CrawlerStorageDir  string        `json:"crawler_storage_dir" env:"STEAM_CRAWLER_STORAGE_DIR"` // HTML存储基础目录
}

SteamConfig Steam 客户端核心配置结构体 整合 API 基础配置、代理配置、速率限制和爬虫专属配置, 支持环境变量注入 SteamConfig is the core configuration structure for Steam client Integrates API basic config, proxy config, rate limit and crawler-specific config, supports environment variable injection

func NewDefaultConfig

func NewDefaultConfig() *SteamConfig

NewDefaultConfig 创建默认配置实例 优先从环境变量读取配置, 未配置则使用 util 包中定义的默认值 返回值:

  • *SteamConfig: 初始化后的配置实例 | Initialized config instance

func (*SteamConfig) Validate

func (c *SteamConfig) Validate() error

Validate 校验配置合法性 检查API Key、超时时间、爬虫相关配置的合法性 返回值:

  • error: 配置非法时返回错误, 合法则返回nil | Error if config invalid, nil if valid

func (*SteamConfig) WithAPIKey

func (c *SteamConfig) WithAPIKey(apiKey string) *SteamConfig

WithAPIKey 自定义API Key 参数:

  • apiKey: Steam API 密钥 | Steam API key

返回值:

  • *SteamConfig: 配置实例(支持链式调用) | Config instance (chain call supported)

WithAPIKey 自定义API Key

func (*SteamConfig) WithCrawlerAsync

func (c *SteamConfig) WithCrawlerAsync(async bool) *SteamConfig

WithCrawlerAsync 自定义爬虫是否异步 参数:

  • async: 是否异步 | Whether to enable async

返回值:

  • *SteamConfig: 配置实例 | Config instance

func (*SteamConfig) WithCrawlerConcurrency

func (c *SteamConfig) WithCrawlerConcurrency(concurrency int) *SteamConfig

WithCrawlerConcurrency 自定义爬虫并发数 参数:

  • concurrency: 并发数(仅接受 >0 的值) | Concurrency count (only >0 accepted)

返回值:

  • *SteamConfig: 配置实例 | Config instance

func (*SteamConfig) WithCrawlerCookie

func (c *SteamConfig) WithCrawlerCookie(cookie string) *SteamConfig

WithCrawlerCookie 自定义爬虫Cookie 参数:

  • cookie: Steam 登录Cookie | Steam login cookie

返回值:

  • *SteamConfig: 配置实例 | Config instance

func (*SteamConfig) WithCrawlerDelay

func (c *SteamConfig) WithCrawlerDelay(delay time.Duration) *SteamConfig

WithCrawlerDelay 自定义爬虫请求延迟 参数:

  • delay: 请求延迟时长 | Request delay duration

返回值:

  • *SteamConfig: 配置实例 | Config instance

func (*SteamConfig) WithCrawlerMaxDepth

func (c *SteamConfig) WithCrawlerMaxDepth(depth int) *SteamConfig

WithCrawlerMaxDepth 自定义爬虫最大深度 参数:

  • depth: 爬取深度(仅接受 >0 的值) | Crawl depth (only >0 accepted)

返回值:

  • *SteamConfig: 配置实例 | Config instance

func (*SteamConfig) WithCrawlerRateLimit

func (c *SteamConfig) WithCrawlerRateLimit(qps float64, burst int) *SteamConfig

WithCrawlerRateLimit 自定义爬虫速率限制 参数:

  • qps: 爬虫每秒请求数 | Crawler requests per second
  • burst: 爬虫突发请求上限 | Crawler burst request limit

返回值:

  • *SteamConfig: 配置实例 | Config instance

func (*SteamConfig) WithCrawlerStorageDir

func (c *SteamConfig) WithCrawlerStorageDir(dir string) *SteamConfig

WithCrawlerStorageDir 自定义爬虫HTML存储目录 参数:

  • dir: 存储目录路径 | Storage directory path

返回值:

  • *SteamConfig: 配置实例 | Config instance

func (*SteamConfig) WithCrawlerUA

func (c *SteamConfig) WithCrawlerUA(ua string) *SteamConfig

WithCrawlerUA 自定义爬虫UA 参数:

  • ua: User-Agent 字符串 | User-Agent string

返回值:

  • *SteamConfig: 配置实例 | Config instance

func (*SteamConfig) WithHeaders

func (c *SteamConfig) WithHeaders(headers map[string]string) *SteamConfig

WithHeaders 自定义请求头 参数:

  • headers: 请求头键值对 | Request header key-value pairs

返回值:

  • *SteamConfig: 配置实例 | Config instance

func (*SteamConfig) WithProxyAuth

func (c *SteamConfig) WithProxyAuth(user, pass string) *SteamConfig

WithProxyAuth 设置代理认证信息 修改后自动重建 Transport 参数:

  • user: 代理用户名 | Proxy username
  • pass: 代理密码 | Proxy password

返回值:

  • *SteamConfig: 配置实例 | Config instance

func (*SteamConfig) WithProxyPool

func (c *SteamConfig) WithProxyPool(proxyPool []string) *SteamConfig

WithProxyPool 设置代理IP池 自动清理空值和空格 参数:

  • proxyPool: 代理地址列表 | Proxy address list

返回值:

  • *SteamConfig: 配置实例 | Config instance

func (*SteamConfig) WithProxyStrategy

func (c *SteamConfig) WithProxyStrategy(strategy string) *SteamConfig

WithProxyStrategy 设置代理选择策略 仅支持 round_robin/random,非法值默认使用 round_robin 参数:

  • strategy: 代理策略 | Proxy strategy

返回值:

  • *SteamConfig: 配置实例 | Config instance

func (*SteamConfig) WithProxyURL

func (c *SteamConfig) WithProxyURL(proxyURL string) *SteamConfig

WithProxyURL 自定义代理地址 修改后自动重建 Transport 参数:

  • proxyURL: 代理地址 | Proxy URL

返回值:

  • *SteamConfig: 配置实例 | Config instance

func (*SteamConfig) WithRateLimit

func (c *SteamConfig) WithRateLimit(qps float64, burst int) *SteamConfig

WithRateLimit 自定义API限流 参数:

  • qps: 每秒请求数 | Requests per second
  • burst: 突发请求上限 | Burst request limit

返回值:

  • *SteamConfig: 配置实例 | Config instance

func (*SteamConfig) WithRetryTimes

func (c *SteamConfig) WithRetryTimes(retryTimes int) *SteamConfig

WithRetryTimes 自定义重试次数 参数:

  • retryTimes: 重试次数(仅接受 >=0 的值) | Retry count (only >=0 accepted)

返回值:

  • *SteamConfig: 配置实例 | Config instance

func (*SteamConfig) WithTimeout

func (c *SteamConfig) WithTimeout(timeout time.Duration) *SteamConfig

WithTimeout 自定义超时时间 参数:

  • timeout: 超时时长 | Timeout duration

返回值:

  • *SteamConfig: 配置实例 | Config instance

Jump to

Keyboard shortcuts

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