The commands go build
and go install
compile the files into binaries. Does go run
compile or interpret the file? I couldn't find explanations online and may have missed it. Appreciate pointers. Thanks!
To run a go program, create a file with an extension .go and write your golang code in that file. For example, we will create a file named helloworld.go and write the following code in it. Now open command prompt and navigate to the location of helloworld.go file.
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. There must be more to it than that - if I time the println in a helloworld, it runs faster with go run than compiled.
Source code for a program written in Go, a programming language originally developed by Google; contains code written in plain text format that must be compiled before being run as a program. Go is loosely based off of the programming language C, which uses the . C file extension for its source code.
If you are trying to run multiple files on localhost using gorilla mux in go as per latest version(1.11). Try using any of the following 2 commands. go install && FolderName -port 8081 . go build && ./FolderName -port 8081.
It's more or less the equivalent of running go build X.go -o /tmp/random-tmp-folder/exe && /tmp/random-tmp-folder/exe
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With