在Revel应用程序中读取“public”文件内容。

huangapple go评论73阅读模式
英文:

Read "public" file content in a Revel app

问题

我目前正在使用Revel编写一个Go Web应用程序。

我的应用程序需要读取存储在服务器上的XML文件的内容。目前,我将这个文件存储在“public”文件夹中,该文件夹中还有其他资源(css、js等)。

我使用ioutil.ReadFile来读取这个文件的内容。当服务器从主应用程序文件夹本身运行时,这个方法可以正常工作,但是当服务器从另一个位置运行时(例如从$GOPATH运行“revel run myapp”),我无法找到访问该文件的方法。

在Revel中有没有处理这种情况的方法?是否有一种通用的方法来获取“public”文件夹的路径?

任何提示都将不胜感激。

谢谢! 在Revel应用程序中读取“public”文件内容。

英文:

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! 在Revel应用程序中读取“public”文件内容。

答案1

得分: 3

应用程序的基本路径存储在revel.BasePath中,并且可以通过该路径访问。

因此,“public”文件夹可以通过revel.BasePath + "/public/<...>"进行访问。

例如,在Static.Serve中使用了这个BasePath值。

英文:

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.

huangapple
  • 本文由 发表于 2014年4月12日 02:19:41
  • 转载请务必保留本文链接:https://go.coder-hub.com/23019905.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定