After installing the GO environment:
- A tool for editing code. Any text editor will do. Most text editors have good support for Go. The most popular are VSCode(free), GoLand (paid) and Vim (free).
- Command line terminal. Go runs properly on any terminal, such as Linux and Mac, as well as CMD on PowerShell or Windows.
Create a new file in your directory, main.go, and type the following code
package main
import "fmt"
func main(a) {
fmt.Println("Hello, World!")}Copy the code
Package main: Declare a main package
Import “FMT” : references the popular FMT package that contains the ability to format text, including printing to the console. This package is a standard library package that is built into the Go installation
Func main() : Go program entry function, each program has a main function;
Run the following command
$ go run main.go
Copy the code
The output is as follows:
$ hello, world!
Copy the code