diff options
| author | Peter Stone <thepeterstone@gmail.com> | 2026-01-12 09:27:16 -1000 |
|---|---|---|
| committer | Peter Stone <thepeterstone@gmail.com> | 2026-01-12 09:27:16 -1000 |
| commit | 9fe0998436488537a8a2e8ffeefb0c4424b41c60 (patch) | |
| tree | ce877f04e60a187c2bd0e481e80298ec5e7cdf80 /internal/config | |
Initial commit: Personal Consolidation Dashboard (Phase 1 Complete)
Implemented a unified web dashboard aggregating tasks, notes, and meal planning:
Core Features:
- Trello integration (PRIMARY feature - boards, cards, lists)
- Todoist integration (tasks and projects)
- Obsidian integration (20 most recent notes)
- PlanToEat integration (optional - 7-day meal planning)
- Mobile-responsive web UI with auto-refresh (5 min)
- SQLite caching with 5-minute TTL
- AI agent endpoint with Bearer token authentication
Technical Implementation:
- Go 1.21+ backend with chi router
- Interface-based API client design for testability
- Parallel data fetching with goroutines
- Graceful degradation (partial data on API failures)
- .env file loading with godotenv
- Comprehensive test coverage (9/9 tests passing)
Bug Fixes:
- Fixed .env file not being loaded at startup
- Fixed nil pointer dereference with optional API clients (typed nil interface gotcha)
Documentation:
- START_HERE.md - Quick 5-minute setup guide
- QUICKSTART.md - Fast track setup
- SETUP_GUIDE.md - Detailed step-by-step instructions
- PROJECT_SUMMARY.md - Complete project overview
- CLAUDE.md - Guide for Claude Code instances
- AI_AGENT_ACCESS.md - AI agent design document
- AI_AGENT_SETUP.md - Claude.ai integration guide
- TRELLO_AUTH_UPDATE.md - New Power-Up auth process
Statistics:
- Binary: 17MB
- Code: 2,667 lines
- Tests: 5 unit + 4 acceptance tests (all passing)
- Dependencies: chi, sqlite3, godotenv
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Diffstat (limited to 'internal/config')
| -rw-r--r-- | internal/config/config.go | 129 |
1 files changed, 129 insertions, 0 deletions
diff --git a/internal/config/config.go b/internal/config/config.go new file mode 100644 index 0000000..4a86b06 --- /dev/null +++ b/internal/config/config.go @@ -0,0 +1,129 @@ +package config + +import ( + "fmt" + "os" + "strconv" +) + +// Config holds all application configuration +type Config struct { + // API Keys + TodoistAPIKey string + PlanToEatAPIKey string + TrelloAPIKey string + TrelloToken string + + // Paths + ObsidianVaultPath string + DatabasePath string + + // Server + Port string + CacheTTLMinutes int + Debug bool + + // AI Agent Access + AIAgentAPIKey string +} + +// Load reads configuration from environment variables +func Load() (*Config, error) { + cfg := &Config{ + // API Keys + TodoistAPIKey: os.Getenv("TODOIST_API_KEY"), + PlanToEatAPIKey: os.Getenv("PLANTOEAT_API_KEY"), + TrelloAPIKey: os.Getenv("TRELLO_API_KEY"), + TrelloToken: os.Getenv("TRELLO_TOKEN"), + + // Paths + ObsidianVaultPath: os.Getenv("OBSIDIAN_VAULT_PATH"), + DatabasePath: getEnvWithDefault("DATABASE_PATH", "./dashboard.db"), + + // Server + Port: getEnvWithDefault("PORT", "8080"), + CacheTTLMinutes: getEnvAsInt("CACHE_TTL_MINUTES", 5), + Debug: getEnvAsBool("DEBUG", false), + + // AI Agent Access + AIAgentAPIKey: os.Getenv("AI_AGENT_API_KEY"), + } + + // Validate required fields + if err := cfg.Validate(); err != nil { + return nil, err + } + + return cfg, nil +} + +// Validate checks that required configuration is present +func (c *Config) Validate() error { + // Require both Todoist and Trello (primary task management systems) + if c.TodoistAPIKey == "" { + return fmt.Errorf("TODOIST_API_KEY is required") + } + + if c.TrelloAPIKey == "" { + return fmt.Errorf("TRELLO_API_KEY is required") + } + + if c.TrelloToken == "" { + return fmt.Errorf("TRELLO_TOKEN is required") + } + + return nil +} + +// HasPlanToEat checks if PlanToEat is configured +func (c *Config) HasPlanToEat() bool { + return c.PlanToEatAPIKey != "" +} + +// HasTrello checks if Trello is configured +func (c *Config) HasTrello() bool { + return c.TrelloAPIKey != "" && c.TrelloToken != "" +} + +// HasObsidian checks if Obsidian is configured +func (c *Config) HasObsidian() bool { + return c.ObsidianVaultPath != "" +} + +// getEnvWithDefault returns environment variable value or default if not set +func getEnvWithDefault(key, defaultValue string) string { + if value := os.Getenv(key); value != "" { + return value + } + return defaultValue +} + +// getEnvAsInt returns environment variable as int or default if not set or invalid +func getEnvAsInt(key string, defaultValue int) int { + valueStr := os.Getenv(key) + if valueStr == "" { + return defaultValue + } + + value, err := strconv.Atoi(valueStr) + if err != nil { + return defaultValue + } + + return value +} + +// getEnvAsBool returns environment variable as bool or default if not set +func getEnvAsBool(key string, defaultValue bool) bool { + valueStr := os.Getenv(key) + if valueStr == "" { + return defaultValue + } + + value, err := strconv.ParseBool(valueStr) + if err != nil { + return defaultValue + } + + return value +} |
