config

package
v0.4.0-beta Latest Latest
Warning

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

Go to latest
Published: May 3, 2026 License: MIT Imports: 10 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package config provides configuration loading and management.

Index

Constants

View Source
const (
	ImageFormatBase64   = "base64"
	ImageFormatLocalURL = "local_url"
)

Variables

View Source
var BrowserUAMap = map[string]string{
	"chrome_133":  "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36",
	"chrome_144":  "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36",
	"chrome_146":  "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/146.0.0.0 Safari/537.36",
	"firefox_135": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:135.0) Gecko/20100101 Firefox/135.0",
	"firefox_147": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:147.0) Gecko/20100101 Firefox/147.0",
}

BrowserUAMap maps browser fingerprint names to their paired User-Agent strings. Browser and UA must always be used as a pair.

Functions

func EffectiveBlockedParallelEnabled

func EffectiveBlockedParallelEnabled(cfg *ImageConfig) bool

EffectiveBlockedParallelEnabled resolves the image toggle with the runtime default.

func EffectiveImageFormat

func EffectiveImageFormat(cfg *ImageConfig) string

func EnsureAdminAppKey

func EnsureAdminAppKey(cfg *Config, entropy io.Reader) (string, bool, error)

EnsureAdminAppKey injects a temporary in-memory admin app_key when none is configured. The generated key is process-local and must not be persisted by callers.

func ValidateImageFormat

func ValidateImageFormat(format string) error

Types

type AppConfig

type AppConfig struct {
	AppKey                 string   `toml:"app_key"`
	MediaGenerationEnabled bool     `toml:"media_generation_enabled"`
	Temporary              bool     `toml:"temporary"`
	DisableMemory          bool     `toml:"disable_memory"`
	Stream                 bool     `toml:"stream"`
	Thinking               bool     `toml:"thinking"`
	DynamicStatsig         bool     `toml:"dynamic_statsig"`
	CustomInstruction      string   `toml:"custom_instruction"`
	FilterTags             []string `toml:"filter_tags"`
	// Model catalog settings
	ModelsFile string `toml:"models_file"` // optional external model catalog file path
	// Server settings
	Host          string `toml:"host"`
	Port          int    `toml:"port"`
	LogJSON       bool   `toml:"log_json"`
	LogLevel      string `toml:"log_level"`
	LogFilePath   string `toml:"log_file_path"`
	LogMaxSizeMB  int    `toml:"log_max_size_mb"`
	LogMaxBackups int    `toml:"log_max_backups"`
	// Database settings
	DBDriver       string `toml:"db_driver"`
	DBPath         string `toml:"db_path"`
	DBDSN          string `toml:"db_dsn"`
	RequestTimeout int    `toml:"request_timeout"` // default request timeout in seconds (non-LLM routes)
	// Security settings
	ReadHeaderTimeout int   `toml:"read_header_timeout"` // seconds, max time to read request headers
	MaxHeaderBytes    int   `toml:"max_header_bytes"`    // max size of request headers in bytes
	BodyLimit         int64 `toml:"body_limit"`          // default max request body size in bytes
	ChatBodyLimit     int64 `toml:"chat_body_limit"`     // max body size for chat completions in bytes
	AdminMaxFails     int   `toml:"admin_max_fails"`     // max auth failures before temporary IP lockout
	AdminWindowSec    int   `toml:"admin_window_sec"`    // time window in seconds for counting admin auth failures
}

AppConfig contains application settings.

type CacheConfig

type CacheConfig struct {
	ImageMaxMB int `toml:"image_max_mb" json:"image_max_mb"`
	VideoMaxMB int `toml:"video_max_mb" json:"video_max_mb"`
}

CacheConfig contains cache management settings.

type Config

type Config struct {
	App   AppConfig   `toml:"app"`
	Image ImageConfig `toml:"image"`
	Proxy ProxyConfig `toml:"proxy"`
	Retry RetryConfig `toml:"retry"`
	Token TokenConfig `toml:"token"`
	Cache CacheConfig `toml:"cache"`
}

Config is the root configuration structure.

func Clone

func Clone(cfg *Config) *Config

Clone deep-copies a configuration tree so callers can mutate safely.

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig returns the default configuration.

func Load

func Load(path string) (*Config, error)

Load loads configuration from the given path. If the file does not exist, returns default configuration.

func (*Config) ApplyDBOverrides

func (c *Config) ApplyDBOverrides(kvs map[string]string) error

ApplyDBOverrides applies database config entries on top of file-based config. Priority: DB > config file > defaults.

type ImageConfig

type ImageConfig struct {
	NSFW                    bool   `toml:"nsfw"`
	Format                  string `toml:"format"`
	BlockedParallelAttempts int    `toml:"blocked_parallel_attempts"`
	BlockedParallelEnabled  *bool  `toml:"blocked_parallel_enabled"`
}

ImageConfig contains image-generation behavior flags.

type ProxyConfig

type ProxyConfig struct {
	BaseProxyURL       string `toml:"base_proxy_url"`
	AssetProxyURL      string `toml:"asset_proxy_url"`
	CFCookies          string `toml:"cf_cookies"`
	SkipProxySSLVerify bool   `toml:"skip_proxy_ssl_verify"`
	Enabled            bool   `toml:"enabled"`
	FlareSolverrURL    string `toml:"flaresolverr_url"`
	RefreshInterval    int    `toml:"refresh_interval"`
	Timeout            int    `toml:"timeout"`
	CFClearance        string `toml:"cf_clearance"`
	Browser            string `toml:"browser"`
	UserAgent          string `toml:"user_agent"`
}

ProxyConfig contains proxy settings.

type RetryConfig

type RetryConfig struct {
	MaxTokens               int     `toml:"max_tokens"`
	PerTokenRetries         int     `toml:"per_token_retries"`
	ResetSessionStatusCodes []int   `toml:"reset_session_status_codes"`
	RetryBackoffBase        float64 `toml:"retry_backoff_base"`
	RetryBackoffFactor      float64 `toml:"retry_backoff_factor"`
	RetryBackoffMax         float64 `toml:"retry_backoff_max"`
	RetryBudget             float64 `toml:"retry_budget"`
}

RetryConfig contains retry policy settings.

type Runtime

type Runtime struct {
	// contains filtered or unexported fields
}

Runtime provides atomic access to the live configuration snapshot.

func NewRuntime

func NewRuntime(cfg *Config) *Runtime

NewRuntime creates a runtime config container initialized with a deep copy.

func (*Runtime) Get

func (r *Runtime) Get() *Config

Get returns the current immutable configuration snapshot.

func (*Runtime) Snapshot

func (r *Runtime) Snapshot() *Config

Snapshot returns a deep copy of the current configuration.

func (*Runtime) Store

func (r *Runtime) Store(cfg *Config)

Store replaces the current config with a cloned copy.

func (*Runtime) Update

func (r *Runtime) Update(fn func(*Config) error) error

Update clones the current config, applies fn, and atomically swaps it in.

type TokenConfig

type TokenConfig struct {
	FailThreshold         int    `toml:"fail_threshold"`
	UsageFlushIntervalSec int    `toml:"usage_flush_interval_sec"`
	SelectionAlgorithm    string `toml:"selection_algorithm" json:"selection_algorithm"`
	MaxInflight           int    `toml:"max_inflight"`
	RecentUsePenaltySec   int    `toml:"recent_use_penalty_sec" json:"recent_use_penalty_sec"`
}

TokenConfig contains token pool settings.

Jump to

Keyboard shortcuts

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