Help us shape the future of Go! Take the 2026 Go Developer Survey

config

package
v0.55.1 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package config handles configuration for multiple providers.

Index

Constants

View Source
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 Bool added in v0.33.0

func Bool(value bool) *bool

func PollInterval added in v0.54.0

func PollInterval(seconds int) time.Duration

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 DefaultConfig

func DefaultConfig() *Config

DefaultConfig returns a default 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

func (c *Config) IsProviderDisabled(name string) bool

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

func (c *Config) IsProviderExplicitlyEnabled(name string) bool

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

func (c *Config) ShouldCheckForUpdates() bool

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 CredentialRef struct {
	Kind string `yaml:"kind"`
	Ref  string `yaml:"ref,omitempty"`
}

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.

Jump to

Keyboard shortcuts

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