展示框架中的相对路径 [英] Relative paths in revel framework

查看:88
本文介绍了展示框架中的相对路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在revel框架中将实际文件导入到revel basefolder.目前,我正在执行以下操作以掌握一些配置值.

How can import a file realtive to the revel basefolder in revel framework. Currently I do the following to get hold of some config values.

file, err := ioutil.ReadFile("conf/config.conf")
...

这导致我的服务器仅在启动

This results in my server only working if i stand in the app directory when starting revel with

revel run myapp

是否可以访问基本文件夹?

Is there a way to access the base folder?

推荐答案

There are exported global variables in the revel package, you can use any of these:

var (
    // App details
    AppName    string // e.g. "sample"
    BasePath   string // e.g. "/Users/revel/gocode/src/corp/sample"
    AppPath    string // e.g. "/Users/revel/gocode/src/corp/sample/app"
    ViewsPath  string // e.g. "/Users/revel/gocode/src/corp/sample/app/views"
    ImportPath string // e.g. "corp/sample"
    SourcePath string // e.g. "/Users/revel/gocode/src"

    // Revel installation details
    RevelPath string // e.g. "/Users/revel/gocode/src/revel"

    // Where to look for templates and configuration.
    // Ordered by priority.  (Earlier paths take precedence over later paths.)
    CodePaths     []string
    ConfPaths     []string
    TemplatePaths []string
)

如果它对您而言是空的,则最有可能是因为您是从基本文件夹中启动应用的.

If it is empty for you, that is most likely because you started your app from the base folder.

请注意,这些路径是由 Init(mode, importPath, srcPath string) 设置的功能.它的文档说明:

Note that these paths are set by the Init(mode, importPath, srcPath string) function. It's documentation states:

srcPath - the path to the source directory, containing Revel and the app.
  If not specified (""), then a functioning Go installation is required.

也请查看:如何引用亲戚代码和测试中的文件

这篇关于展示框架中的相对路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆