Documentation
¶
Overview ¶
Package config handles application configuration loading and validation.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ResolveConfigPath ¶
func ResolveConfigPath() string
ResolveConfigPath determines which config file to load.
func WatchConfig ¶
func WatchConfig(ctx context.Context, atomic *AtomicConfig) error
WatchConfig monitors the config file for changes and reloads it automatically. It watches the directory containing the config file (not the file itself) to handle editors that save by renaming/creating a new file. It also listens for SIGHUP to allow manual reload triggers on Unix systems.
Types ¶
type AtomicConfig ¶
type AtomicConfig struct {
// contains filtered or unexported fields
}
AtomicConfig provides thread-safe access to the configuration with support for hot reloading. It uses atomic.Pointer for lock-free reads.
func NewAtomicConfig ¶
func NewAtomicConfig(cfg *Config, path string) *AtomicConfig
NewAtomicConfig creates a new AtomicConfig with the given initial config and file path.
func (*AtomicConfig) Get ¶
func (a *AtomicConfig) Get() *Config
Get returns the current configuration pointer. This is safe for concurrent use. Callers must not modify the returned Config.
func (*AtomicConfig) OnReload ¶
func (a *AtomicConfig) OnReload(fn func(*Config))
OnReload registers a callback that will be invoked after each successful reload.
func (*AtomicConfig) Path ¶
func (a *AtomicConfig) Path() string
Path returns the config file path being watched.
func (*AtomicConfig) Reload ¶
func (a *AtomicConfig) Reload() error
Reload reloads the configuration from disk and atomically swaps it in. If the reload fails, the old configuration is preserved and an error is returned. On successful reload, all registered callbacks are invoked.
type Config ¶
type Config struct {
APIKey string `json:"api_key"`
APIKeys []string `json:"api_keys"`
Host string `json:"host"`
Port int `json:"port"`
HotReload bool `json:"hot_reload"`
EnableStreamingScenarioRouting bool `json:"enable_streaming_scenario_routing"`
RespectRequestedModel *bool `json:"respect_requested_model,omitempty"`
Models map[string]ModelConfig `json:"models"`
Fallbacks map[string][]ModelConfig `json:"fallbacks"`
ModelOverrides map[string]ModelConfig `json:"model_overrides"`
OpenCodeGo OpenCodeGoConfig `json:"opencode_go"`
OpenCodeZen OpenCodeZenConfig `json:"opencode_zen"`
Logging LoggingConfig `json:"logging"`
}
Config holds the complete application configuration.
func Load ¶
Load reads configuration from a JSON file and applies environment variable overrides. Config path resolution:
- ROUTATIC_PROXY_CONFIG env var (explicit override)
- OC_GO_CC_CONFIG env var (legacy explicit override)
- ~/.config/routatic-proxy/config.json (default)
- ~/.config/oc-go-cc/config.json (legacy fallback when the new path is absent)
func LoadFromPath ¶
LoadFromPath reads configuration from the given JSON file path.
func (*Config) EffectiveAPIKeys ¶
EffectiveAPIKeys returns the pool of API keys for rotation. APIKeys takes precedence; falls back to the single APIKey field.
type LoggingConfig ¶
LoggingConfig controls application logging behavior.
type ModelConfig ¶
type ModelConfig struct {
Provider string `json:"provider"`
ModelID string `json:"model_id"`
WireFormat string `json:"wire_format,omitempty"` // "auto" (default), "openai", "anthropic", "responses", "gemini"
Temperature float64 `json:"temperature"`
MaxTokens int `json:"max_tokens"`
ContextThreshold int `json:"context_threshold"`
ReasoningEffort string `json:"reasoning_effort"`
Thinking json.RawMessage `json:"thinking,omitempty"`
Vision bool `json:"vision"`
AnthropicToolsDisabled bool `json:"anthropic_tools_disabled"`
}
ModelConfig defines routing rules for a specific model.
type OpenCodeGoConfig ¶
type OpenCodeGoConfig struct {
BaseURL string `json:"base_url"`
AnthropicBaseURL string `json:"anthropic_base_url"`
TimeoutMs int `json:"timeout_ms"`
StreamTimeoutMs int `json:"stream_timeout_ms"`
}
OpenCodeGoConfig holds the upstream OpenCode Go API settings.
type OpenCodeZenConfig ¶
type OpenCodeZenConfig struct {
BaseURL string `json:"base_url"`
AnthropicBaseURL string `json:"anthropic_base_url"`
ResponsesBaseURL string `json:"responses_base_url"`
GeminiBaseURL string `json:"gemini_base_url"`
TimeoutMs int `json:"timeout_ms"`
StreamTimeoutMs int `json:"stream_timeout_ms"`
}
OpenCodeZenConfig holds the upstream OpenCode Zen API settings.