go build vs go run
go build builds the command and leaves the result in the current working directory.

Example :
Summary
The go build command compiles a Go program into an executable file, while go run compiles and executes the program in one step, without leaving an executable file in the current directory.
Abstract
The article discusses the differences between the go build and go run commands in the Go programming language. go build is used to compile a Go program into an executable file that can be run independently without the need to recompile for subsequent executions. On the other hand, go run is a convenience command that compiles the code and immediately executes it, which is particularly useful for developers who need to test and iterate on their code quickly. The article also mentions that the execution time for go run is comparable to running an executable directly, especially for small programs that fit in the L2 cache. Additionally, the Go community's collaborative nature is highlighted by contributions from developers like Pascal Dennerly and Peter Hellberg, who shared tips such as using the -o flag with go build to specify the output directory for the binary.
Opinions
go build is suitable for creating executables that users can interact with, as it compiles the program once and does not require recompilation for each run.go run command is presented as a developer-friendly tool for quickly checking the output of code changes without the overhead of manually compiling and running the executable each time.go run is similar to running the compiled executable, which is efficient for small programs.go build -o DirectoryPath to control where the binary is output, showcasing the Go community's collaborative and helpful spirit.
Example :
go build main.go
Above program will be able to turn into an executable file that will always print out “Hello World”. If we want our program to run again, we don’t have to compile the program again, we simply run the executable file. Therefore, if we want fast code that users interact with, we’d compile a program once and use the executable file.
go run main.go
If we ever wanted to modify our program? compiling another executable file and then running that file would not be ideal. And imagine if we have to do that every single time just to check a small change or fix an error! 😱
Amazingly, there is another command comes handy which is go run command followed by the name of the Go program. The go run command combines both the compilation and execution of code. This allows to quickly check the output of updated code.
go run will NOT create an executable file in our current folder.
Update 05/02/2020 :
Another amazing Go developer Pascal Dennerly shared his experience from his projects which is the time it takes execute program go run is same as running the executable admittedly they all fit in the L2 cache.
go build -o DirectoryPath
Go community is awesome. Another Go developer Peter Hellberg introduced me to another parameter -o followed by go build allows to output binary to a specified location
Kartik ButtanError handling is a core part of any programming language. It’s a way to prevent our applications from silently failing, to catch…