我使用 Google Cloud SQL 和 MySQL 服务器开发了一些 GO 库。当我导入 `appengine/cloudsql 时,出现以下错误。
cloud.go:20:2: 在以下任何一个中找不到包“appengine/cloudsql”:
/usr/local/Cellar/go/1.1.2/src/pkg/appengine/cloudsql(来自 $GOROOT)
/Users/lameduck/myGo/src/appengine/cloudsql(来自 $GOPATH)
我知道这个包 appengine/cloudsql
仅适用于 Google App Engine,其他任何地方都不存在。
我想知道如何在单个库中将它用于 GAE 和其他环境的标准 sql 库。
PS:我可以正确设置 Google App Engine SDK。我的问题与此无关。我希望我的库可以同时在 Google App Engine 和独立环境中运行。 (我已经为 GAE 和其他数据库编写了代码。)用户必须设置一些配置是可以的。但我不希望用户必须修改库源代码。
感谢您的帮助。
最佳答案
我解决了这个问题。我用了 build constraint使用正确的例程并避免错误。 App Engine 存在构建约束,appengine .
The App Engine SDK introduces a new build constraint term: "appengine". Files that specify
// +build appengine will be built by the App Engine SDK and ignored by the go tool. Conversely, files that specify
// +build !appengine are ignored by the App Engine SDK, while the go tool will happily build them.
附言: Anway,我赞成其他答案。谢谢。
关于google-app-engine - 找不到包 "appengine/cloudsql",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19852395/