Skip to content

Commit

Permalink
Use the config dir returned by os.UserConfigDir()
Browse files Browse the repository at this point in the history
svanharmelen committed Jan 3, 2025

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 7863f75 commit a1e9873
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions app/config.go
Original file line number Diff line number Diff line change
@@ -26,7 +26,11 @@ func defaultConfig() *Config {
}

func LoadConfig() error {
file, err := os.ReadFile(filepath.Join(os.Getenv("HOME"), ".config", "lazysql", "config.toml"))
configDir, err := os.UserConfigDir()
if err != nil {
return err
}
file, err := os.ReadFile(filepath.Join(configDir, "lazysql", "config.toml"))
if err != nil {
return err
}
@@ -46,11 +50,14 @@ func LoadConfig() error {
func (c *Config) SaveConnections(connections []models.Connection) error {
c.Connections = connections

directoriesPath := filepath.Join(os.Getenv("HOME"), ".config", "lazysql")
configDir, err := os.UserConfigDir()
if err != nil {
return err
}
directoriesPath := filepath.Join(configDir, "lazysql")
configFilePath := filepath.Join(directoriesPath, "config.toml")

err := os.MkdirAll(directoriesPath, 0o755)
if err != nil {
if err = os.MkdirAll(directoriesPath, 0o755); err != nil {
return err
}

0 comments on commit a1e9873

Please sign in to comment.