Documentation
¶
Overview ¶
Package config handles configuration for multiple providers.
Index ¶
- Constants
- func Bool(value bool) *bool
- func PollInterval(seconds int) time.Duration
- type Config
- func (c *Config) EnsureProvider(name string, enabled bool) ProviderConfig
- func (c *Config) GetProvider(name string) (ProviderConfig, bool)
- func (c *Config) IsProviderDisabled(name string) bool
- func (c *Config) IsProviderExplicitlyEnabled(name string) bool
- func (c *Config) Save(validators ...SourceValidator) error
- func (c *Config) ShouldCheckForUpdates() bool
- func (c *Config) ValidateSources(validators ...SourceValidator) error
- type CredentialRef
- type GlobalSettings
- type NotificationConfig
- type ProviderConfig
- type SourceConfig
- type SourceValidator
Constants ¶
const MinimumPollIntervalSeconds = 300
MinimumPollIntervalSeconds bounds automatic tray polling. Manual refreshes remain available when the user needs an immediate reading.
Variables ¶
This section is empty.
Functions ¶
func PollInterval ¶ added in v0.54.0
PollInterval is how often the tray polls for a configured number of seconds, which is never below the minimum.
Types ¶
type Config ¶
type Config struct {
// Providers configuration - keys are provider names (claude, openai, etc.)
Providers map[string]ProviderConfig `yaml:"providers,omitempty"`
// Global settings
Settings GlobalSettings `yaml:"settings,omitempty"`
}
Config holds the application configuration.
func Load ¶
func Load(validators ...SourceValidator) (*Config, error)
Load reads configuration from the config file. Returns default config if file doesn't exist.
If the canonical path is missing but the legacy path (~/.config/clawmeter/config.yaml) is present and differs, Load migrates by copying the legacy file to the canonical path. The legacy file is left in place so a rollback to an older binary still works.
func (*Config) EnsureProvider ¶
func (c *Config) EnsureProvider(name string, enabled bool) ProviderConfig
EnsureProvider creates or updates a provider config.
func (*Config) GetProvider ¶
func (c *Config) GetProvider(name string) (ProviderConfig, bool)
GetProvider returns the config for a specific provider.
func (*Config) IsProviderDisabled ¶
IsProviderDisabled reports whether the user has explicitly turned this provider off. Providers with no config entry are treated as auto-enabled (so detected credentials work without manual setup).
func (*Config) IsProviderExplicitlyEnabled ¶
IsProviderExplicitlyEnabled reports whether the user has explicitly opted a provider into polling in config.
func (*Config) Save ¶
func (c *Config) Save(validators ...SourceValidator) error
Save writes configuration to the config file.
func (*Config) ShouldCheckForUpdates ¶
configPath returns the canonical path to the config file: the platform-appropriate user config dir, plus clawmeter/config.yaml.
On Linux this is $XDG_CONFIG_HOME/clawmeter/config.yaml (typically ~/.config/clawmeter/config.yaml); on macOS it is ~/Library/Application Support/clawmeter/config.yaml; on Windows it is %APPDATA%\clawmeter\config.yaml. ShouldCheckForUpdates reports whether automatic GitHub release checks are enabled.
func (*Config) ValidateSources ¶ added in v0.33.0
func (c *Config) ValidateSources(validators ...SourceValidator) error
type CredentialRef ¶ added in v0.33.0
type GlobalSettings ¶
type GlobalSettings struct {
// PollInterval for the tray (in seconds)
PollInterval int `yaml:"poll_interval,omitempty"`
// CheckForUpdates controls automatic GitHub release checks from the tray.
CheckForUpdates *bool `yaml:"check_for_updates,omitempty"`
// NotificationThresholds for usage warnings
NotificationThresholds NotificationConfig `yaml:"notification_thresholds,omitempty"`
}
GlobalSettings holds application-wide settings.
type NotificationConfig ¶
type NotificationConfig struct {
Warning float64 `yaml:"warning"` // Default: 80%; persist explicit zero.
Critical float64 `yaml:"critical,omitempty"` // Default: 95%
}
NotificationConfig holds notification settings.
type ProviderConfig ¶
type ProviderConfig struct {
// Enabled determines if this provider is active
Enabled bool `yaml:"enabled"`
// APIKey for services that use API key authentication
APIKey string `yaml:"api_key,omitempty"`
// OAuthToken for services that use OAuth
OAuthToken string `yaml:"oauth_token,omitempty"`
// Extra holds provider-specific configuration
Extra map[string]interface{} `yaml:"extra,omitempty"`
// Sources are explicit credential or quota-observation routes. They are
// displayed independently; Clawmeter never infers that their quotas combine.
// The credential reference is opaque to the core and interpreted by the
// provider adapter that owns it.
Sources []SourceConfig `yaml:"sources,omitempty"`
}
ProviderConfig holds configuration for a single provider.
type SourceConfig ¶ added in v0.33.0
type SourceConfig struct {
ID string `yaml:"id"`
Label string `yaml:"label,omitempty"`
Enabled *bool `yaml:"enabled,omitempty"`
Credential CredentialRef `yaml:"credential"`
}
func (SourceConfig) IsEnabled ¶ added in v0.33.0
func (s SourceConfig) IsEnabled() bool
type SourceValidator ¶ added in v0.33.0
type SourceValidator func(family string, sources []SourceConfig) error
SourceValidator applies provider-owned selector rules without coupling the neutral config package to provider implementations.