From 49ddd56e3db6f499a083069d19901943a9e1709f Mon Sep 17 00:00:00 2001 From: Nathan Coad Date: Fri, 13 Sep 2024 16:48:17 +1000 Subject: [PATCH] fix when running from absolute path --- components/home/home.templ | 1 + internal/utils/utils.go | 4 ++-- main.go | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/components/home/home.templ b/components/home/home.templ index f089c7d..809175e 100644 --- a/components/home/home.templ +++ b/components/home/home.templ @@ -4,5 +4,6 @@ templ Home() {

Welcome!

This is a simple home screen.

+

{ buildTime }

} diff --git a/internal/utils/utils.go b/internal/utils/utils.go index fd2e074..5f7057a 100644 --- a/internal/utils/utils.go +++ b/internal/utils/utils.go @@ -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) diff --git a/main.go b/main.go index 964c72f..b9662c3 100644 --- a/main.go +++ b/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)