Make go run dev work :3
This commit is contained in:
28
main.go
28
main.go
@@ -9,19 +9,33 @@ import (
|
||||
"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"
|
||||
}
|
||||
|
||||
exePath, err := os.Executable()
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
exeDir := filepath.Dir(exePath)
|
||||
templateDir := filepath.Join(exeDir, "templates")
|
||||
|
||||
templateDir := getTemplateDir()
|
||||
|
||||
tmpl, err := template.ParseFiles(
|
||||
filepath.Join(templateDir, "layout.html"),
|
||||
|
Reference in New Issue
Block a user