英文:
Is it possible to generate code in a module after downloading it?
问题
正如标题所说,是否可能在下载模块依赖之后生成代码(类似于//go:generate
)?
具体来说,假设有一个名为example.com/protobuf
的仓库,其中包含一些.proto
文件和几个用于生成不同语言绑定的.sh
脚本,还有一个go.mod
文件,以便可以将其作为依赖从Go中使用,如下所示:
module example.com/application
go 1.18
require (
example.com/protobuf v1.0.0
)
然而,生成的.go
文件不包含在这个仓库中,它们必须使用其中一个.sh
脚本生成,因此如果尝试这样做,会出现错误,例如module example.com/protobuf@latest found (v1.0.0), but does not contain package example.com/protobuf/foo
。
是否有一种方法可以解决这个问题,而不必使用git子模块之类的方法?
英文:
As the title says, is it possible to generate code (with something like //go:generate
) after a module dependency is downloaded?
Specifically, let's say there's a repo example.com/protobuf
containing some .proto
files and a few .sh
scripts for generating bindings in different languages, plus a go.mod
so it can be used as a dependency from go like so:
module example.com/application
go 1.18
require (
example.com/protobuf v1.0.0
)
However, the generated .go
files are not included in this repo, they have to be generated using one of the .sh
scripts, so if you try this, you get an error like module example.com/protobuf@latest found (v1.0.0), but does not contain package example.com/protobuf/foo
Is there a way around this without resorting to eg. git submodules?
答案1
得分: 2
不,出于明显的安全原因,这是不可能的。
英文:
No this is not possible for obvious security reasons.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论