问题描述
error loading config file: open go-config.json: no such file or directory
这是handlers.go
中的go代码段
config := config{}
err := gonfig.GetConf("go-config.json",&config)
if err != nil {
log.Printf("error loading config file: %v\n",err)
}
runtime: go114
service: finance
在应用程序引擎的调试器上,我看到项目结构看起来像这样。
app engine:/
quantify
app.yaml
config.go
go-config.json
main.go
handlers.go
quantify
为什么我不能在已部署的应用程序代码中读取此文件?我曾尝试以多种方式在app.yaml
中指定处理程序,但均未成功。
解决方法
首先,您应该通过fmt.Println(os.Getwd())
找出当前路径
fmt.Println(os.Getwd())
config := config{}
err := gonfig.GetConf("go-config.json",&config)
if err != nil {
log.Printf("error loading config file: %v\n",err)
}
然后将“ go-config.json”更改为当前路径的相对路径