Files
nexus/internal/config/config.go
T
Andy DixonandClaude Sonnet 5 1a380a0e99 Rebrand: Nexus Terminal → Alchementary Link
Renames the product across the codebase: Go module path, config/data
paths, keychain service name, export file extension, build tooling,
docs, and UI text. Sidebar brand mark now reads ">_ AlchementaryLink"
with "Alchementary" in the connection-group gold accent colour, and
the window title is "Alchementary Link".

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019T8bJS8BCtY5GeSG2HBj1n
2026-09-03 16:41:23 +01:00

88 lines
2.0 KiB
Go

// Package config resolves platform-specific application paths and configuration.
package config
import (
"os"
"path/filepath"
"runtime"
)
const appName = "AlchementaryLink"
// AppConfig holds the resolved application configuration paths.
type AppConfig struct {
DataDir string // base data directory
DBPath string // SQLite database path
SecretPath string // encrypted vault directory
LogPath string // log file path
}
// Load resolves the application configuration.
// Data directory follows platform conventions:
// - macOS: ~/Library/Application Support/AlchementaryLink
// - Linux: ~/.config/AlchementaryLink
// - Windows: %APPDATA%/AlchementaryLink
func Load() (*AppConfig, error) {
dataDir, err := resolveDataDir()
if err != nil {
return nil, err
}
cfg := &AppConfig{
DataDir: dataDir,
DBPath: filepath.Join(dataDir, "link.db"),
SecretPath: filepath.Join(dataDir, "vault"),
LogPath: filepath.Join(dataDir, "link.log"),
}
return cfg, nil
}
// EnsureDirectories creates required directories if they don't exist.
func (c *AppConfig) EnsureDirectories() error {
dirs := []string{
c.DataDir,
c.SecretPath,
filepath.Dir(c.LogPath),
}
for _, d := range dirs {
if err := os.MkdirAll(d, 0700); err != nil {
return err
}
}
return nil
}
// resolveDataDir determines the base data directory for the current platform.
func resolveDataDir() (string, error) {
var base string
switch runtime.GOOS {
case "darwin":
home, err := os.UserHomeDir()
if err != nil {
return "", err
}
base = filepath.Join(home, "Library", "Application Support")
case "windows":
base = os.Getenv("APPDATA")
if base == "" {
home, err := os.UserHomeDir()
if err != nil {
return "", err
}
base = filepath.Join(home, "AppData", "Roaming")
}
default: // Linux and other UNIX-likes
base = os.Getenv("XDG_CONFIG_HOME")
if base == "" {
home, err := os.UserHomeDir()
if err != nil {
return "", err
}
base = filepath.Join(home, ".config")
}
}
return filepath.Join(base, appName), nil
}