Golang - Difference between “go run main.go” and compilation

 ̄綄美尐妖づ 提交于 2019-12-21 03:29:29

问题


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:


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:


'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




回答3:


For DEV (local) environment - use go run,
For PROD environment - use go install this one better than go build because it installs packages and dependencies and you'll have Go toolchain.



来源:https://stackoverflow.com/questions/28881706/golang-difference-between-go-run-main-go-and-compilation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!