英文:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论