Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Go: How does go run file.go work

Tags:

go

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!

like image 485
user3918985 Avatar asked Feb 27 '15 01:02

user3918985


People also ask

How do I run a go program?

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.

What is go run main go?

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.

What is a .go file?

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.

How do I run multiple files on go?

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.


1 Answers

It's more or less the equivalent of running go build X.go -o /tmp/random-tmp-folder/exe && /tmp/random-tmp-folder/exe

like image 137
OneOfOne Avatar answered Sep 24 '22 07:09

OneOfOne