[英]Subfolders and packages when using Appengine and Go
When deploying and/or testing a Go project for appengine, the appcfg.py and dev_appserver.py tools are used to compile the project在为 appengine 部署和/或测试 Go 项目时,appcfg.py 和 dev_appserver.py 工具用于编译项目
That works fine when all the *.go files are in one folder, but how can a project be be compiled when code is divided into subfolders- yet also need to access functions and constants from eachother?当所有 *.go 文件都在一个文件夹中时,这可以正常工作,但是当代码分为子文件夹时如何编译项目 - 还需要相互访问函数和常量?
In Go- subfolders are by definition package boundaries, and I can't see a way to allow the appengine tools to compile multiple packages before testing or deploying, from one project.在 Go 中,子文件夹根据定义是包边界,我看不出有一种方法可以让 appengine 工具在测试或部署之前从一个项目编译多个包。
Advice on how to tackle this- other than keeping it all in one folder, is appreciated.关于如何解决这个问题的建议 - 除了将所有内容都保存在一个文件夹中之外,我们不胜感激。 Even if the solution is to approach it one package (folder) at a time, advice on how to structure that for quick iteration on one project that uses all those packages is appreciated.
即使解决方案是一次处理一个包(文件夹),关于如何构建一个使用所有这些包的项目的快速迭代的建议也是值得赞赏的。 Thanks!
谢谢!
There is no magic here.这里没有魔法。 Just make sure each of your go files is placed in a folder and not in the root of your appengine project.
只需确保您的每个 go 文件都放在一个文件夹中,而不是放在 appengine 项目的根目录中。
For example:例如:
-[Project root]
app.yaml
-[packagea]
packagea.go
-[packageab]
packageab.go
-[packageb]
packageb.go
In the example above, package declarations should be as follows:在上面的示例中,包声明应如下所示:
packagea.go:包a.go:
package packagea
packageab.go packageab.go
package packageab
packageb.go包b.go
package packageb
And for example if packageb
uses both packagea
and packageab
, import them as:例如,如果
packageb
使用packagea
和packageab
,请将它们导入为:
packageb.go:包b.go:
import ( "packagea" "packagea/packageab" )
Note:笔记:
Note that you cannot create an import cycle (eg packagea
imports packageb
, and packageb
imports packagea
):请注意,您不能创建导入循环(例如
packagea
导入packageb
,并且packageb
导入packagea
):
Spec: Import declarations规范:进口申报
An import declaration declares a dependency relation between the importing and imported package.
导入声明声明了导入包和导入包之间的依赖关系。 It is illegal for a package to import itself, directly or indirectly.
包直接或间接导入自身是非法的。
You have to structure your code and packages to avoid import cycles or your code will not compile.您必须构建代码和包以避免导入循环,否则您的代码将无法编译。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.