Use runtime.Caller() to locate the frontend files path
authorRobert Sesek <rsesek@bluestatic.org>
Sun, 7 Oct 2012 13:53:10 +0000 (09:53 -0400)
committerRobert Sesek <rsesek@bluestatic.org>
Sun, 7 Oct 2012 13:53:10 +0000 (09:53 -0400)
server/server.go

index e5874a71368bac68bf44cb3f2fa7ed52ea20df2f..66c3c3c6c9ff6ef57d0369ddae93e97e8511fcea 100644 (file)
 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"))