package config import ( "os" "path/filepath" "runtime" ) // DefaultPath returns the default location for the YAML config file. On // Windows we follow the same convention as the legacy WinAuth and use // %APPDATA%\winauth-go\config.yaml. On other platforms we honor // $XDG_CONFIG_HOME (falling back to ~/.config) and use the standard // winauth-go subdirectory. func DefaultPath() string { if p := envConfigPath(); p != "" { return p } if runtime.GOOS == "windows" { if dir := os.Getenv("APPDATA"); dir != "" { return filepath.Join(dir, "winauth-go", "config.yaml") } } if dir := os.Getenv("XDG_CONFIG_HOME"); dir != "" { return filepath.Join(dir, "winauth-go", "config.yaml") } if home, err := os.UserHomeDir(); err == nil { return filepath.Join(home, ".config", "winauth-go", "config.yaml") } return "winauth.yaml" } func envConfigPath() string { return os.Getenv("WINAUTH_GO_CONFIG") } // EnsureDir creates the parent directory of path with 0o700 permissions // (best effort). Returns nil if creation succeeds or the directory already // exists. func EnsureDir(path string) error { return os.MkdirAll(filepath.Dir(path), 0o700) }