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

2019-04-03 13:04发布

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?

3条回答
女痞
2楼-- · 2019-04-03 13:18

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.

查看更多
啃猪蹄的小仙女
3楼-- · 2019-04-03 13:28

'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

查看更多
贪生不怕死
4楼-- · 2019-04-03 13:37

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.

查看更多
登录 后发表回答