I'm trying to split my application files from my testing files. It looks something like this:
main.go
views/
layouts/
layout.html
spec/
main_test.go
main.go
creates a Martini app and tells Martini.render
where to look for the views:
func CreateApplication() {
m := martini.Classic()
m.Use(render.Renderer(render.Options{
Directory: "views",
Layout: "layouts/layout",
Extensions: []string{".html"},
}))
}
That all works really well when I'm using go run
from the root folder. However, when I try to use the CreateApplication()
function from the spec/main_test.go
file, it's now looking for the views in spec/views
because that's the run folder.
I went down the route of trying to use runtime.Caller()
to get the absolute path, but that totally messes up when compilling the a binary.
I guess my question is how I can make this work? I want that CreateApplication()
to work the same no matter where it was called from.