英文:
Read "public" file content in a Revel app
问题
我目前正在使用Revel编写一个Go Web应用程序。
我的应用程序需要读取存储在服务器上的XML文件的内容。目前,我将这个文件存储在“public”文件夹中,该文件夹中还有其他资源(css、js等)。
我使用ioutil.ReadFile来读取这个文件的内容。当服务器从主应用程序文件夹本身运行时,这个方法可以正常工作,但是当服务器从另一个位置运行时(例如从$GOPATH运行“revel run myapp”),我无法找到访问该文件的方法。
在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!
答案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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论