In order to tell Go that this is a Go module, you will need to create a Go module using the go mod command:
go mod init greeter
In order to tell Go that this is a Go module, you will need to create a Go module using the go mod command:
go mod init greeter
Let’s take a closer look at the module method. If you had a go.mod file in your project with a module declaration such as the following:
module github.com/sammy/shark
If you are running macOS or Linux, you will find a new executable file that has been named after the directory in which you built your program:
Outputgreeter main.go
Run the following go build command with the -o flag:
go build -o bin/hello
Now run the install command:
go install
To find where your $GOPATH directory is located, run the following command:
go env GOPATH
The output you receive will vary, but the default is the go directory inside of your $HOME directory:
Output$HOME/go
Now, that you’ve created your executable, run it to make sure the binary has been built correctly. On macOS or Linux, run the following command:
./greeter
The output of the binary will match the output from when you ran the program with go run:
OutputHello, World!
This will build your binary and place it in $GOPATH/bin. To test this, run the following:
ls $GOPATH/bin
Recommend
How To Build and Install Go Programs Step 1 — Setting Up and Running the Go Binary
How To Set Up Let's Encrypt with Nginx Server Blocks on Ubuntu 16.04 Step 1 — Installing Certbot
Comment utiliser Go avec MongoDB en utilisant le pilote MongoDB Go Étape 8 — Suppression d’une tâche
Comment utiliser Go avec MongoDB en utilisant le pilote MongoDB Go Étape 5 — Fin d’une tâche
Comment utiliser Go avec MongoDB en utilisant le pilote MongoDB Go Étape 3 — Création d’une tâche
Comment utiliser Go avec MongoDB en utilisant le pilote MongoDB Go Conditions préalables
Lidando com a função Panics em Go Detectando panics com o recover