AppConfigDir returns the directory where to store user's config. If XDG_CONFIG_HOME is set, it returns: $XDG_CONFIG_HOME/caddy. Otherwise, os.UserConfigDir() is used; if successful, it appends "Caddy" (Windows & Mac) or "caddy" (every other OS) to the path. If it returns an error, the fallback path
()
| 84 | // |
| 85 | // Ref: https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html |
| 86 | func AppConfigDir() string { |
| 87 | if basedir := os.Getenv("XDG_CONFIG_HOME"); basedir != "" { |
| 88 | return filepath.Join(basedir, "caddy") |
| 89 | } |
| 90 | basedir, err := os.UserConfigDir() |
| 91 | if err != nil { |
| 92 | Log().Warn("unable to determine directory for user configuration; falling back to current directory", zap.Error(err)) |
| 93 | return "./caddy" |
| 94 | } |
| 95 | subdir := "caddy" |
| 96 | switch runtime.GOOS { |
| 97 | case "windows", "darwin": |
| 98 | subdir = "Caddy" |
| 99 | } |
| 100 | return filepath.Join(basedir, subdir) |
| 101 | } |
| 102 | |
| 103 | // AppDataDir returns a directory path that is suitable for storing |
| 104 | // application data on disk. It uses the environment for finding the |
no test coverage detected