From 79cb09919c479ca68a363d131a55d0840fad8f8a Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Sun, 7 Oct 2012 09:53:10 -0400 Subject: [PATCH] Use runtime.Caller() to locate the frontend files path --- server/server.go | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/server/server.go b/server/server.go index e5874a7..66c3c3c 100644 --- a/server/server.go +++ b/server/server.go @@ -10,19 +10,30 @@ package server import ( - "github.com/rsesek/armadillo/config" "encoding/json" "fmt" + "github.com/rsesek/armadillo/config" "io" "net/http" "os" "path" + "runtime" "strings" ) -var dir, file = path.Split(path.Clean(os.Getenv("_"))) -var kFrontEndFiles string = path.Join(dir, "frontend") -var gConfig *config.Configuration +var ( + kFrontEndFiles string + gConfig *config.Configuration +) + +func init() { + _, thisFile, _, ok := runtime.Caller(0) + if !ok { + panic("unable to get file information from runtime.Caller so the frontend files cannot be found") + } + // thisFile = /armadillo/server/server.go, so compute /armadillo/frontend/ + kFrontEndFiles = path.Join(path.Dir(path.Dir(thisFile)), "frontend") +} func indexHandler(response http.ResponseWriter, request *http.Request) { fd, err := os.Open(path.Join(kFrontEndFiles, "index.html")) -- 2.43.5