Skip to content

Instantly share code, notes, and snippets.

@Alexisvt
Last active August 17, 2020 01:29
Show Gist options
  • Save Alexisvt/e34218271bd83633606d546412a23746 to your computer and use it in GitHub Desktop.
Save Alexisvt/e34218271bd83633606d546412a23746 to your computer and use it in GitHub Desktop.
Some useful go commands

List of useful go commands

go help

Display useful information about the different commands available. If we need more information about an specific command, type:

# Where [command] can be any of the available commands
go help [command]

If we want to see the whole list of commands available, just type:

go help

go mod

This command handle all the differents operations of a module, for example, if we want to initialize a mod inside a current folder, we can run:

go mod init

Check all the differents options with go help mod command

go run

This command build and run the application and discard the binary file, example:

go run main.go

Note: We have to use this command over a file that use the main package, If not, we will receive an error: cannot run non-main package.

go build

This command build and creates a binary or an executable next to the file where we are using this command, if the file is using the main package, if not it will compile the file but it wont generate anything.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment