go - Google App Engine - 从应用程序代码中读取 JSON 文件
问题描述
在我部署的一个应用程序引擎中,我收到以下错误。
error loading config file: open go-config.json: no such file or directory
这是 go 代码的片段handlers.go
config := config{}
err := gonfig.GetConf("go-config.json", &config)
if err != nil {
log.Printf("error loading config file: %v\n", err)
}
这是我的app.yaml
文件
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”更改为与当前路径相关的路径
推荐阅读
- ios - 如何使用 Swift 为 JSON 数据创建 JSON Codable 和 Decodable?
- c++ - Eigen:我应该使用对齐的地图进行密集计算吗?
- mongodb - 无法在 Ubuntu 系统中运行 MongoDB 服务器
- c# - 是否有像 `dotnet new react` 这样的 Blazor WASM + WebAPI 项目模板?
- php - 如何使用wordpress创建多区域网站
- c# - 尝试运行 Specflow 测试但返回错误 - 已指定单元测试提供程序
- java - 如何使用 exchangeatesapi.io 和 okhttp 更改汇率基础货币,并在微调器中选择所有基础货币?
- java - java.lang.ClassNotFoundException:org.apache.poi.POIXMLTypeLoader 错误
- php - 使用无限滚动时如何获取最后加载的 ID,按列组合两个日期列排序?
- firebase - 使用flutter将多张图片上传到firestore并获取它的下载URL并将所有URL保存到firebase