1

I am currently writing a Go web app using Revel.

My app needs to read the content of an XML file which is stored on the server. At the moment, I store this file in the "public" folder where some other resources (css, js...) lie.

I am using ioutil.ReadFile to read the content of this file. While this is working when the server is run from the main app folder itself, I cannot figure how to access the file when the server is run from another location (say by running "revel run myapp" from $GOPATH).

Is there any way to deal with this situation in revel? is there a generic way to know the path of the "public" folder?

Any hint would be appreciated.

Thanks! :)

Uraza
  • 556
  • 3
  • 17
  • 1
    It doesn't seem to be possible without either using absolute paths (which would change when you deploy), or bundling the data with your binary. See this answer for a possible workaround: http://stackoverflow.com/a/17100221 – Attila O. Apr 11 '14 at 18:57
  • Thanks for your feedback Attila. I have just found out how to achieve what I want on Revel. I will post the explanation below for clarity. – Uraza Apr 11 '14 at 20:34

1 Answers1

3

The base path of the application is stored and accessible through revel.BasePath.

The "public" folder can thus be accessed through revel.BasePath + "/public/<...>".

This BasePath value is used, for example, in Static.Serve.

Uraza
  • 556
  • 3
  • 17