aboutsummaryrefslogtreecommitdiff
path: root/core/assets/path.go
diff options
context:
space:
mode:
Diffstat (limited to 'core/assets/path.go')
-rw-r--r--core/assets/path.go29
1 files changed, 29 insertions, 0 deletions
diff --git a/core/assets/path.go b/core/assets/path.go
new file mode 100644
index 000000000..46b883b1c
--- /dev/null
+++ b/core/assets/path.go
@@ -0,0 +1,29 @@
+package assets
+
+import (
+ "os"
+ "path/filepath"
+ "runtime"
+)
+
+// Path returns the path to the folder
+// where the application may store data. This
+// currently resolves to ~/.caddy
+func Path() string {
+ return filepath.Join(userHomeDir(), ".caddy")
+}
+
+// userHomeDir returns the user's home directory according to
+// environment variables.
+//
+// Credit: http://stackoverflow.com/a/7922977/1048862
+func userHomeDir() string {
+ if runtime.GOOS == "windows" {
+ home := os.Getenv("HOMEDRIVE") + os.Getenv("HOMEPATH")
+ if home == "" {
+ home = os.Getenv("USERPROFILE")
+ }
+ return home
+ }
+ return os.Getenv("HOME")
+}