This repository has been archived by the owner on Apr 28, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
63407d1
commit f4d59ee
Showing
6 changed files
with
93 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,62 +1,14 @@ | ||
package config | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
"runtime" | ||
) | ||
|
||
const ( | ||
PAGINATION_COUNT = 20 | ||
|
||
app_name = "slashbase" | ||
app_db_file = "app.db" | ||
app_name = "slashbase" | ||
app_db_file = "app.db" | ||
app_env_file = ".env" | ||
|
||
BUILD_PRODUCTION = "production" | ||
BUILD_DEVELOPMENT = "development" | ||
|
||
DEFAULT_SERVER_PORT = "22022" | ||
) | ||
|
||
func GetAppDatabaseFilePath() string { | ||
if !IsLive() { | ||
return app_db_file | ||
} | ||
var filePath string | ||
if runtime.GOOS == "windows" { | ||
// Get the %LOCALAPPDATA% path | ||
localAppData := os.Getenv("LOCALAPPDATA") | ||
// Set the file name and path | ||
filePath = filepath.Join(localAppData, app_name, app_db_file) | ||
} else if runtime.GOOS == "darwin" { | ||
// Get the user's home directory | ||
homeDir, err := os.UserHomeDir() | ||
if err != nil { | ||
panic(err) | ||
} | ||
filePath = filepath.Join(homeDir, "Library", "Application Support", app_name, app_db_file) | ||
} else if runtime.GOOS == "linux" { | ||
filePath = filepath.Join("/usr/local", app_name, app_db_file) | ||
} else { | ||
panic(errors.New("not implemented")) | ||
} | ||
err := os.MkdirAll(filepath.Dir(filePath), 0700) | ||
if err != nil { | ||
panic(err) | ||
} | ||
ex, err := os.Executable() | ||
if err != nil { | ||
panic(err) | ||
} | ||
exPath, _ := filepath.EvalSymlinks(ex) | ||
exPath = filepath.Dir(exPath) | ||
exPath = exPath + "/" + app_db_file | ||
if _, err := os.Stat(exPath); !os.IsNotExist(err) { | ||
if err := os.Rename(exPath, filePath); err != nil { | ||
fmt.Println(err) | ||
} | ||
} | ||
return filePath | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters