Encountering some peculiar file path issues in my Go project. Here's how the file structure is laid out:
C:/ProjectName/
-------------->bin/
-------------->pkg/
-------------->src/web/
---------------------->main.go
---------------------->controllers/Constants.go
---------------------->content/css/index.css
---------------------->views/index.html
My Go environment variables are set as follows:
GOBIN=C:\ProjectName\bin
GOPATH=C:\ProjectName
In the index.html
file, I reference the CSS file using
<link href="/css/index.css"...
, but it fails to locate the css
file.Similarly, in the
Constants.go
file, I try to access the html
file with const indexFile string = "../src/web/views/index.htm"
, which also proves unsuccessful.
If I access the css
file as /content/css/index.css
, it works fine. Likewise, referencing the index.html
file as "../web/views/index.htm"
also resolves the issue.
The predicament lies in the fact that while this approach works on my computer, it causes failures on other team members' machines. Every attempt to make it run smoothly on mine results in breaking for everyone else.
Any insights on identifying the root cause and rectifying this matter would be greatly appreciated.
Thank you,
EDIT 1: Overview of my handlers
router := httprouter.New()
router.GET(basic("/", IndexFunc))
func basic(p string, h func(http.ResponseWriter, *http.Request)) (string,
httprouter.Handle) {
return p, wrapHandler(alice.New(context.ClearHandler).ThenFunc(h))
}
func IndexFunc(w http.ResponseWriter, r *http.Request)
{
t, err := template.ParseFiles("../src/web/views/index.htm")
checkError(err)
t.Execute(w, nil)
}
References:
alice -> https://github.com/justinas/alice
context -> https://github.com/gorilla/context
The function indexFunc
essentially serves the index.html
file.