如何在App Engine模块之间共享文件(HTML模板)?

问题描述:

I am using the Go runtime of Google App Engine and have two modules. I would like to share HTML templates between them but don't the best way.

My modules are organised as below:

src/github.com/myproject/moduleone/app.yaml
src/github.com/myproject/moduleone/templates/base.html
src/github.com/myproject/moduleone/templates/homeone.html

src/github.com/myproject/moduletwo/app.yaml
src/github.com/myproject/moduletwo/templates/base.html
src/github.com/myproject/moduletwo/templates/hometwo.html

In my situation base.html is the same for moduleone and moduletwo. How can I share it between both modules without having to duplicate the file as is done now?

I would like to put base.html in a directory called src/github.com/myproject/templates but I believe neither moduleone or moduletwo would be able to access the file as it's not in the same or child directory of the module app.yaml files. Is my only option to symlink the base.html file between each module's template directory?

我正在使用Google App Engine的Go运行时,并且有两个模块。 我想在它们之间共享HTML模板,但不是最好的方法。 p>

我的模块结构如下: p>

  src  /github.com/myproject/moduleone/app.yaml
src/github.com/myproject/moduleone/templates/base.html
src/github.com/myproject/moduleone/templates/homeone.html

src/github 的.com / myproject的/ ModuleTWO中/ app.yaml中\ NSRC / github.com / myproject的/ ModuleTWO中/模板/ base.html文件\ NSRC / github.com / myproject的/ ModuleTWO中/模板/ hometwo.html 
 代码>   pre> 
 
 

在我的情况下, base.html code>与 moduleone code>和 moduletwo code>相同。 我如何在两个模块之间共享它而又不必像现在那样复制文件? p>

我想将 base.html code>放在一个名为 src / github.com / myproject / templates code>,但我相信 moduleone code>或 moduletwo code>都无法访问该文件,因为它不在同一文件中或 模块 app.yaml code>文件的子目录。 我唯一的选择是在每个模块的模板目录之间符号链接 base.html code>文件吗? p> div>

GAE regards each module as a standalone application (each will run in its own GAE instance). No uploadable artifacts are shared at GAE level between the modules, each such artifact needs to be separately uploaded in each module using it.

While other approaches are technically possible (as other mentioned) symlinking the files is IMHO the simplest solution to avoid code duplication in your own repo.

You could copy the templates to each module as part of a build step and gitignore the copied files.