go build命令的等效API是什么?

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

go build command equivalent api

问题

要在Go中编译插件,您需要运行以下命令:

go build -buildmode=plugin

是否可以调用一些内部API来代替命令行选项来执行此操作?我可以始终打包Go二进制文件并调用os.exec("<CMD>"),但如果可能的话,我想避免这样做。

英文:

To compile a plugin in go I need to run the command below.

go build -buildmode=plugin

Is it possible to call some internal API instead of the command-line option to do this? I can always package the go binary and call os.exec("<CMD>") but I want to avoid that if I can.

答案1

得分: 1

由于Go是用Go构建的,因此你可以从go/internal(https://pkg.go.dev/std请参见internal)开始查找。这是一个兔子洞,但包含了所有的项目,如环境变量(GOOS)、构建配置、Go根目录等。

其他一些为了立即使用而构建代码的项目(如skaffold)似乎选择了os.Exec

英文:

Since go is build with go, the go/internal (https://pkg.go.dev/std see internal) place is where you want to start looking. It is a rabbit hole but contains all the items like environment variables (GOOS), build config, go root, etc.

Other projects building some code for immediate usage (like skaffold) seem to have opted for os.Exec

huangapple
  • 本文由 发表于 2022年7月23日 06:18:08
  • 转载请务必保留本文链接:https://go.coder-hub.com/73086573.html
匿名

发表评论

匿名网友

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

确定