Skip to content

Commit

Permalink
Tune AppConfigDir and docs for Storage module
Browse files Browse the repository at this point in the history
  • Loading branch information
mholt committed Jan 1, 2020
1 parent 788462b commit 06ea0a5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
9 changes: 4 additions & 5 deletions caddy.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,10 @@ type Config struct {
Logging *Logging `json:"logging,omitempty"`

// StorageRaw is a storage module that defines how/where Caddy
// stores assets (such as TLS certificates). By default, this is
// the local file system (`caddy.storage.file_system` module).
// If the `XDG_DATA_HOME` environment variable is set, then
// `$XDG_DATA_HOME/caddy` is the default folder. Otherwise,
// `$HOME/.local/share/caddy` is the default folder.
// stores assets (such as TLS certificates). The default storage
// module is `caddy.storage.file_system` (the local file system),
// and the default path
// [depends on the OS and environment](/docs/conventions#data-directory).
StorageRaw json.RawMessage `json:"storage,omitempty" caddy:"namespace=caddy.storage inline_key=module"`

// AppsRaw are the apps that Caddy will load and run. The
Expand Down
15 changes: 7 additions & 8 deletions storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,13 @@ func homeDirUnsafe() string {
//
// Ref: https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html
func AppConfigDir() string {
basedir := os.Getenv("XDG_CONFIG_HOME")
if basedir == "" {
var err error
basedir, err = os.UserConfigDir()
if err != nil {
Log().Warn("unable to determine directory for user configuration; falling back to current directory", zap.Error(err))
return "./caddy"
}
if basedir := os.Getenv("XDG_CONFIG_HOME"); basedir != "" {
return filepath.Join(basedir, "caddy")
}
basedir, err := os.UserConfigDir()
if err != nil {
Log().Warn("unable to determine directory for user configuration; falling back to current directory", zap.Error(err))
return "./caddy"
}
subdir := "caddy"
switch runtime.GOOS {
Expand Down

0 comments on commit 06ea0a5

Please sign in to comment.