style: Apply code formatting with go fmt
- Run 'make format' to ensure all Go code follows standard formatting - Maintains consistent code style across the entire codebase - No functional changes, only whitespace and formatting improvements
This commit is contained in:
parent
4fd0846127
commit
2bffa2c418
19 changed files with 543 additions and 527 deletions
|
|
@ -17,17 +17,17 @@ func ResolveDatabasePath(configPath string) (string, error) {
|
|||
}
|
||||
return configPath, nil
|
||||
}
|
||||
|
||||
|
||||
// Try system location first (for services)
|
||||
if systemPath, err := trySystemPath(); err == nil {
|
||||
return systemPath, nil
|
||||
}
|
||||
|
||||
|
||||
// Try user data directory
|
||||
if userPath, err := tryUserPath(); err == nil {
|
||||
return userPath, nil
|
||||
}
|
||||
|
||||
|
||||
// Fallback to current directory
|
||||
return tryCurrentDirPath()
|
||||
}
|
||||
|
|
@ -35,7 +35,7 @@ func ResolveDatabasePath(configPath string) (string, error) {
|
|||
// trySystemPath attempts to use system-wide database location
|
||||
func trySystemPath() (string, error) {
|
||||
var systemDir string
|
||||
|
||||
|
||||
switch runtime.GOOS {
|
||||
case "linux":
|
||||
systemDir = "/var/lib/skyview"
|
||||
|
|
@ -46,26 +46,26 @@ func trySystemPath() (string, error) {
|
|||
default:
|
||||
return "", fmt.Errorf("system path not supported on %s", runtime.GOOS)
|
||||
}
|
||||
|
||||
|
||||
// Check if directory exists and is writable
|
||||
if err := ensureDirExists(systemDir); err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
|
||||
dbPath := filepath.Join(systemDir, "skyview.db")
|
||||
|
||||
|
||||
// Test write permissions
|
||||
if err := testWritePermissions(dbPath); err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
|
||||
return dbPath, nil
|
||||
}
|
||||
|
||||
// tryUserPath attempts to use user data directory
|
||||
func tryUserPath() (string, error) {
|
||||
var userDataDir string
|
||||
|
||||
|
||||
switch runtime.GOOS {
|
||||
case "linux":
|
||||
if xdgData := os.Getenv("XDG_DATA_HOME"); xdgData != "" {
|
||||
|
|
@ -91,20 +91,20 @@ func tryUserPath() (string, error) {
|
|||
default:
|
||||
return "", fmt.Errorf("user path not supported on %s", runtime.GOOS)
|
||||
}
|
||||
|
||||
|
||||
skyviewDir := filepath.Join(userDataDir, "skyview")
|
||||
|
||||
|
||||
if err := ensureDirExists(skyviewDir); err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
|
||||
dbPath := filepath.Join(skyviewDir, "skyview.db")
|
||||
|
||||
|
||||
// Test write permissions
|
||||
if err := testWritePermissions(dbPath); err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
|
||||
return dbPath, nil
|
||||
}
|
||||
|
||||
|
|
@ -114,14 +114,14 @@ func tryCurrentDirPath() (string, error) {
|
|||
if err != nil {
|
||||
return "", fmt.Errorf("cannot get current directory: %v", err)
|
||||
}
|
||||
|
||||
|
||||
dbPath := filepath.Join(currentDir, "skyview.db")
|
||||
|
||||
|
||||
// Test write permissions
|
||||
if err := testWritePermissions(dbPath); err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
|
||||
return dbPath, nil
|
||||
}
|
||||
|
||||
|
|
@ -134,23 +134,23 @@ func ensureDirExists(dir string) error {
|
|||
} else if err != nil {
|
||||
return fmt.Errorf("cannot access directory %s: %v", dir, err)
|
||||
}
|
||||
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// testWritePermissions verifies write access to the database path
|
||||
func testWritePermissions(dbPath string) error {
|
||||
dir := filepath.Dir(dbPath)
|
||||
|
||||
|
||||
// Check directory write permissions
|
||||
testFile := filepath.Join(dir, ".skyview_write_test")
|
||||
if err := os.WriteFile(testFile, []byte("test"), 0644); err != nil {
|
||||
return fmt.Errorf("no write permission to directory %s: %v", dir, err)
|
||||
}
|
||||
|
||||
|
||||
// Clean up test file
|
||||
os.Remove(testFile)
|
||||
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
@ -171,4 +171,4 @@ func IsSystemPath(dbPath string) bool {
|
|||
return programData != "" && filepath.HasPrefix(dbPath, filepath.Join(programData, "skyview"))
|
||||
}
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue