OSDN Git Service

Merge pull request #906 from freewind/improve-data-dir
authorPaladz <yzhu101@uottawa.ca>
Mon, 7 May 2018 10:34:36 +0000 (18:34 +0800)
committerGitHub <noreply@github.com>
Mon, 7 May 2018 10:34:36 +0000 (18:34 +0800)
Improve the code to determine default data dir

config/config.go

index a902337..5fe31e6 100644 (file)
@@ -198,18 +198,17 @@ func rootify(path, root string) string {
 func DefaultDataDir() string {
        // Try to place the data folder in the user's home dir
        home := homeDir()
-       dataDir := "./.bytom"
-       if home != "" {
-               switch runtime.GOOS {
-               case "darwin":
-                       dataDir = filepath.Join(home, "Library", "Bytom")
-               case "windows":
-                       dataDir = filepath.Join(home, "AppData", "Roaming", "Bytom")
-               default:
-                       dataDir = filepath.Join(home, ".bytom")
-               }
+       if home == "" {
+               return "./.bytom"
+       }
+       switch runtime.GOOS {
+       case "darwin":
+               return filepath.Join(home, "Library", "Bytom")
+       case "windows":
+               return filepath.Join(home, "AppData", "Roaming", "Bytom")
+       default:
+               return filepath.Join(home, ".bytom")
        }
-       return dataDir
 }
 
 func homeDir() string {