无法找到包”appengine/cloudsql”。

huangapple go评论72阅读模式
英文:

cannot find package "appengine/cloudsql"

问题

我使用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编写了一段代码,为其他数据库编写了另一段代码)。用户需要设置一些配置是可以的,但我不希望用户修改库源代码。

感谢任何帮助。

英文:

I develop some GO libraries using Google Cloud SQL and MySQL server. When I imported `appengine/cloudsql, an error below occured.

cloud.go:20:2: cannot find package "appengine/cloudsql" in any of:
	/usr/local/Cellar/go/1.1.2/src/pkg/appengine/cloudsql (from $GOROOT)
	/Users/lameduck/myGo/src/appengine/cloudsql (from $GOPATH)

I know this package, appengine/cloudsql, is only for Google App Engine and it doesn't exist on everywhere else.

I'm wondering how can I use it for GAE and standard sql library for other environments in a single library.

PS: I can setup Google App Engine SDK correctly. My question is not relevant to it. I hope my library runs on Google App Engine and standalone environment together. (I already made a code for GAE and a code for other dabatases.) It is Ok that users have to setup some configurations. But I don't want that users have to modify a library source code.

Thanks for any help.

答案1

得分: 3

我解决了这个问题。我使用了一个构建约束来使用适当的例程并避免错误。对于App Engine,有一个构建约束叫做appengine

> App Engine SDK引入了一个新的构建约束术语:"appengine"。指定了

> // +build appengine 的文件将由App Engine SDK构建,并被go工具忽略。相反,指定了

> // +build !appengine 的文件将被App Engine SDK忽略,而go工具将愉快地构建它们。

PS:无论如何,我给其他答案点了赞。谢谢。

英文:

I solved the problem. I used a build constraint to use the proper routine and avoid an error. There is a build constraint for 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.

PS:
Anway, I upvoted other answers. Thank you.

答案2

得分: 1

包的导入是在编译/链接时完成的。与Python不同,Go不支持运行时条件导入。

你要寻找的功能是动态库加载(就像在C/C++中可以在运行时加载.so/.dll文件),但是目前Go不支持这个功能。你可以参考这个链接

英文:

Package import is done during compile/link time. And Go doesn't support runtime conditional imports in distinction from Python.

Feature you are looking for is dynamic library loading (like in C/C++ you can load .so/.dll in runtime), but Go currently doesn't support it.

huangapple
  • 本文由 发表于 2013年11月8日 13:43:08
  • 转载请务必保留本文链接:https://go.coder-hub.com/19852395.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定