fix when running from absolute path
This commit is contained in:
@@ -4,5 +4,6 @@ templ Home() {
|
||||
<div class="text-center">
|
||||
<h1 class="text-5xl font-bold">Welcome!</h1>
|
||||
<p class="text-indigo-200 mt-4">This is a simple home screen.</p>
|
||||
<p class="text-indigo-200 mt-4">{ buildTime }</p>
|
||||
</div>
|
||||
}
|
||||
|
@@ -18,11 +18,11 @@ func GetFilePath(path string) string {
|
||||
|
||||
// check if filename exists
|
||||
if _, err := os.Stat(path); os.IsNotExist((err)) {
|
||||
slog.Info("File '%s' not found, searching in same directory as binary", path)
|
||||
slog.Info("File not found, searching in same directory as binary", "filename", path)
|
||||
// if not, check that it exists in the same directory as the currently executing binary
|
||||
ex, err2 := os.Executable()
|
||||
if err2 != nil {
|
||||
slog.Error("Error determining binary path : '%s'", err)
|
||||
slog.Error("Error determining binary path", "error", err)
|
||||
return ""
|
||||
}
|
||||
binaryPath := filepath.Dir(ex)
|
||||
|
2
main.go
2
main.go
@@ -40,7 +40,7 @@ func main() {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
|
||||
// Configure database
|
||||
database, err := db.New(logger, "./db.sqlite3")
|
||||
database, err := db.New(logger, utils.GetFilePath("db.sqlite3"))
|
||||
if err != nil {
|
||||
logger.Error("Failed to create database", "error", err)
|
||||
os.Exit(1)
|
||||
|
Reference in New Issue
Block a user