config

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package config handles loading and managing msgvault configuration.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultHome

func DefaultHome() string

DefaultHome returns the default msgvault home directory. Respects MSGVAULT_HOME environment variable and expands ~ in its value.

func MkTempDir added in v0.6.0

func MkTempDir(pattern string, preferredDirs ...string) (string, error)

MkTempDir creates a temporary directory with fallback logic for restricted environments (e.g. Windows where %TEMP% may be inaccessible due to permissions, antivirus, or group policy).

It tries the following locations in order:

  1. Each directory in preferredDirs (if any)
  2. The system default temp directory (os.TempDir())
  3. A "tmp" subdirectory under the msgvault home directory (~/.msgvault/tmp/)

The first successful location is used. If all locations fail, the error from the system temp dir attempt is returned along with the final fallback error.

Types

type AccountSchedule added in v0.7.0

type AccountSchedule struct {
	Email    string `toml:"email"`    // Gmail account email
	Schedule string `toml:"schedule"` // Cron expression (e.g., "0 2 * * *" for 2am daily)
	Enabled  bool   `toml:"enabled"`  // Whether scheduled sync is active
}

AccountSchedule defines sync schedule for a single account.

type ChatConfig

type ChatConfig struct {
	Server     string `toml:"server"`      // Ollama server URL
	Model      string `toml:"model"`       // Model name
	MaxResults int    `toml:"max_results"` // Top-K messages to retrieve
}

ChatConfig holds chat/LLM configuration.

type Config

type Config struct {
	Data     DataConfig        `toml:"data"`
	OAuth    OAuthConfig       `toml:"oauth"`
	Sync     SyncConfig        `toml:"sync"`
	Chat     ChatConfig        `toml:"chat"`
	Server   ServerConfig      `toml:"server"`
	Accounts []AccountSchedule `toml:"accounts"`

	// Computed paths (not from config file)
	HomeDir string `toml:"-"`
	// contains filtered or unexported fields
}

Config represents the msgvault configuration.

func Load

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

Load reads the configuration from the specified file. If path is empty, uses the default location (~/.msgvault/config.toml), which is optional (missing file returns defaults). If path is explicitly provided, the file must exist.

homeDir overrides the home directory (equivalent to MSGVAULT_HOME). When set, config.toml is loaded from homeDir unless path is also set.

func NewDefaultConfig added in v0.4.0

func NewDefaultConfig() *Config

NewDefaultConfig returns a configuration with default values.

func (*Config) AnalyticsDir

func (c *Config) AnalyticsDir() string

AnalyticsDir returns the path to the Parquet analytics directory.

func (*Config) AttachmentsDir

func (c *Config) AttachmentsDir() string

AttachmentsDir returns the path to the attachments directory.

func (*Config) ConfigFilePath added in v0.5.0

func (c *Config) ConfigFilePath() string

ConfigFilePath returns the path to the config file. If a config was loaded (including via --config), returns the actual path used. Otherwise returns the default location based on HomeDir.

func (*Config) DatabaseDSN added in v0.4.0

func (c *Config) DatabaseDSN() string

DatabaseDSN returns the database connection string or file path.

func (*Config) EnsureHomeDir added in v0.5.0

func (c *Config) EnsureHomeDir() error

EnsureHomeDir creates the msgvault home directory if it doesn't exist.

func (*Config) GetAccountSchedule added in v0.7.0

func (c *Config) GetAccountSchedule(email string) *AccountSchedule

GetAccountSchedule returns the schedule for a specific account email. Returns nil if the account is not configured for scheduling. The returned value is a copy, so mutations won't affect the config.

func (*Config) ScheduledAccounts added in v0.7.0

func (c *Config) ScheduledAccounts() []AccountSchedule

ScheduledAccounts returns accounts with scheduling enabled.

func (*Config) TokensDir

func (c *Config) TokensDir() string

TokensDir returns the path to the OAuth tokens directory.

type DataConfig

type DataConfig struct {
	DataDir     string `toml:"data_dir"`
	DatabaseURL string `toml:"database_url"`
}

DataConfig holds data storage configuration.

type OAuthConfig

type OAuthConfig struct {
	ClientSecrets string `toml:"client_secrets"`
}

OAuthConfig holds OAuth configuration.

type ServerConfig added in v0.7.0

type ServerConfig struct {
	APIPort         int      `toml:"api_port"`         // HTTP server port (default: 8080)
	BindAddr        string   `toml:"bind_addr"`        // Bind address (default: 127.0.0.1)
	APIKey          string   `toml:"api_key"`          // API authentication key
	AllowInsecure   bool     `toml:"allow_insecure"`   // Allow unauthenticated non-loopback access
	CORSOrigins     []string `toml:"cors_origins"`     // Allowed CORS origins (empty = disabled)
	CORSCredentials bool     `toml:"cors_credentials"` // Allow credentials in CORS
	CORSMaxAge      int      `toml:"cors_max_age"`     // Preflight cache duration in seconds (default: 86400)
}

ServerConfig holds HTTP API server configuration.

func (ServerConfig) IsLoopback added in v0.7.0

func (s ServerConfig) IsLoopback() bool

IsLoopback returns true if the bind address is a loopback address. Handles the full 127.0.0.0/8 range, IPv6 ::1, and "localhost".

func (ServerConfig) ValidateSecure added in v0.7.0

func (s ServerConfig) ValidateSecure() error

ValidateSecure returns an error if the server is configured insecurely without an explicit opt-in via allow_insecure.

type SyncConfig

type SyncConfig struct {
	RateLimitQPS int `toml:"rate_limit_qps"`
}

SyncConfig holds sync-related configuration.

Jump to

Keyboard shortcuts

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