HomeToolsAbout

Run and Build

Running Go File/Packages

run compiles then runs a main package comprised of the .go files.

  • The command is compiled to a temporary folder.
# compile and run the go package go run main.go

Runtime playground

https://go.dev/play/

Bootstrapping

These functions are documented for completeness but are not guaranteed to stay in the language. They do not return a result.

// prints all arguments print // like print but prints spaces between arguments and a newline at the end println

Compile

install and build compiles the files into binaries.

# compile the packages named by imports, along with dependencies, but doesn't install the results go build file_path # compiles and installs the packages named by the imports go install file_path

go download vs go build

go mod download is downloading all of the modules in the dependency graph, which it can determine from reading only the go.mod files. It doesn't know which of those modules are actually needed to satisfy a build, so it doesn't pull in the checksums for those modules.

go mod tidy has to walk the package graph in order to ensure that all imports are satisfied. So it knows, for a fact, without doing any extra work, that the modules it walks through are needed for a go build in some configuration.

AboutContact