gpt4 book ai didi

go - revel 框架中的相对路径

转载 作者:IT王子 更新时间:2023-10-29 02:05:13 25 4
gpt4 key购买 nike

如何在 revel 框架中将文件 realtive 导入到 revel basefolder。目前我执行以下操作来获取一些配置值。

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

这导致我的服务器只有在我开始 Revel 时站在应用程序目录中才能工作

revel run myapp

有没有办法访问基本文件夹?

最佳答案

revel中有导出的全局变量包,您可以使用以下任何一种:

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
)

如果它对您来说是空的,那很可能是因为您从基础文件夹启动了您的应用。

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

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

另请查看:how to reference a relative file from code and tests

关于go - revel 框架中的相对路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31265072/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com