How can I share files (HTML templates) between App Engine modules?

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

How can I share files (HTML templates) between App Engine modules?

问题

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

我的模块组织如下:

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

在我的情况下,base.html 对于 moduleonemoduletwo 是相同的。我如何在两个模块之间共享它,而不必像现在这样重复文件?

我想把 base.html 放在一个名为 src/github.com/myproject/templates 的目录中,但我认为 moduleonemoduletwo 都无法访问该文件,因为它不在模块的 app.yaml 文件所在的同一目录或子目录中。我唯一的选择是在每个模块的模板目录之间创建符号链接来共享 base.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?

答案1

得分: 1

GAE将每个模块视为独立的应用程序(每个模块将在自己的GAE实例中运行)。在GAE级别上,没有可上传的工件在模块之间共享,每个这样的工件都需要在使用它的每个模块中单独上传。

虽然其他方法在技术上是可行的(如其他人提到的),但在我看来,使用符号链接文件是避免在您自己的存储库中出现代码重复的最简单解决方案。

英文:

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.

答案2

得分: 1

你可以将模板复制到每个模块作为构建步骤的一部分,并在gitignore中忽略复制的文件。

英文:

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

huangapple
  • 本文由 发表于 2015年10月13日 02:45:02
  • 转载请务必保留本文链接:https://go.coder-hub.com/33088104.html
匿名

发表评论

匿名网友

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

确定