From 050ff9060e076a78db9871107b06aeaa596ac3de Mon Sep 17 00:00:00 2001 From: kisukalat Date: Tue, 23 Sep 2025 19:04:03 +0300 Subject: [PATCH] fix the stupid code --- main.go | 40 ++++++++-------------------------------- 1 file changed, 8 insertions(+), 32 deletions(-) diff --git a/main.go b/main.go index c15fdea..96eba0f 100644 --- a/main.go +++ b/main.go @@ -4,44 +4,20 @@ import ( "html/template" "log" "net/http" - "strings" "path/filepath" - "os" ) -func getTemplateDir() string { - exePath, err := os.Executable() - if err != nil { - log.Fatal(err) - } - exeDir := filepath.Dir(exePath) - - testPath := filepath.Join(exeDir, "templates") - if _, err := os.Stat(testPath); err == nil { - return testPath - } - // if running using: go run use wd - wd, err := os.Getwd() - if err != nil { - log.Fatal(err) - } - return filepath.Join(wd, "templates") -} - func pageHandler(w http.ResponseWriter, r *http.Request) { - path := strings.Trim(r.URL.Path, "/") - if path == "" { - path = "home" - } - - - templateDir := getTemplateDir() + path := r.URL.Path + if path == "/" { + path = "/home" + } tmpl, err := template.ParseFiles( - filepath.Join(templateDir, "layout.html"), - filepath.Join(templateDir, "header.html"), - filepath.Join(templateDir, "footer.html"), - filepath.Join(templateDir, path+".html"), + filepath.Join("templates/layout.html"), + filepath.Join("templates/header.html"), + filepath.Join("templates/footer.html"), + filepath.Join("templates/"+path+".html"), ) if err != nil { http.NotFound(w, r)