-
-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Windows compatibility - Updated GetHomeDir() and notes for running with Admininistrator on Windows to create symlinks. * fix: remove new image from git * fix: remove new image from git --------- Co-authored-by: Sam <[email protected]>
- Loading branch information
Showing
8 changed files
with
105 additions
and
26 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
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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package utils | ||
|
||
import ( | ||
"os" | ||
"path/filepath" | ||
|
||
"github.com/sammcj/gollama/logging" | ||
) | ||
|
||
func GetHomeDir() string { | ||
homeDir, err := os.UserHomeDir() | ||
if err != nil { | ||
logging.ErrorLogger.Printf("Failed to get user home directory: %v\n", err) | ||
|
||
return "" | ||
} | ||
return homeDir | ||
} | ||
|
||
// getConfigDir returns the directory of the configuration JSON file. | ||
func GetConfigDir() string { | ||
return filepath.Join(GetHomeDir(), ".config", "gollama") | ||
} | ||
|
||
// getConfigPath returns the path to the configuration JSON file. | ||
func GetConfigPath() string { | ||
return filepath.Join(GetHomeDir(), ".config", "gollama", "config.json") | ||
} |
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 |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package utils | ||
|
||
import ( | ||
"os" | ||
"path/filepath" | ||
"runtime" | ||
"testing" | ||
) | ||
|
||
func TestGetHomeDir(t *testing.T) { | ||
expected := homeDir() | ||
got := GetHomeDir() | ||
if got != expected { | ||
t.Errorf("GetHomeDir() = %v, want %v", got, expected) | ||
} | ||
} | ||
|
||
func TestGetConfigDir(t *testing.T) { | ||
expected := filepath.Join(homeDir(), ".config", "gollama") | ||
got := GetConfigDir() | ||
if got != expected { | ||
t.Errorf("GetConfigDir() = %v, want %v", got, expected) | ||
} | ||
} | ||
|
||
func TestGetConfigPath(t *testing.T) { | ||
expected := filepath.Join(homeDir(), ".config", "gollama", "config.json") | ||
got := GetConfigPath() | ||
if got != expected { | ||
t.Errorf("GetConfigPath() = %v, want %v", got, expected) | ||
} | ||
} | ||
|
||
func homeDir() string { | ||
// Get User Home directory (simplified). Refer to "os/file" | ||
var env string | ||
if runtime.GOOS == "windows" { | ||
env = "USERPROFILE" | ||
} else { | ||
env = "HOME" | ||
} | ||
if v := os.Getenv(env); v != "" { | ||
return v | ||
} | ||
return "" | ||
} |
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