英文:
Golang - Difference between "go run main.go" and compilation
问题
在使用Go编写一些脚本后,我想知道编译.go
文件和后续执行以及使用go run FILE.go
命令在性能等方面是否有任何区别。
如果我使用其中一种方法启动一个Web服务,是否有任何优势?
英文:
After writing some scripts in Go I asked myself if there is any difference between the compilation of a .go
-file and the later execution and the go run FILE.go
command in terms of performence etc.
Are there any advantages if I start a webservice with one of these methods?
答案1
得分: 60
go run
只是一个编译并在一步中运行的快捷方式。虽然在开发过程中很有用,但在生产环境中使用时,通常应直接构建并运行二进制文件。
英文:
go run
is just a shortcut for compiling then running in a single step. While it is useful for development you should generally build it and run the binary directly when using it in production.
答案2
得分: 7
对于 DEV(本地)环境 - 使用 go run
,
对于 PROD 环境 - 使用 go install
,这个比 go build
更好,因为它会安装包和依赖项,并且你将拥有 Go 工具链。
英文:
For DEV (local) environment - use go run
,
<br>For PROD environment - use go install
this one better than go build
because it installs packages and dependencies and you'll have Go toolchain.
答案3
得分: 6
'go install'命令将在pkg文件夹下创建编译后的共享库文件package.a,并在bin目录下创建可执行文件。
在开发过程中,go run命令非常有用,因为它会为您编译并运行代码,但不会在pkg文件夹和src文件夹中生成二进制文件。
英文:
'go install' command will create shared library compiled file as package.a under pkg folder and exec file under bin directory.
go run command is useful while doing development as it just compiles and run it for you but won't produce binaries in pkg folder and src folder
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论