Your first Go program

After installing the Go tools successfully on your local machine, you are now ready to write and execute your first Go program. For that, simply open your favorite text editor and type in the simple Hello World program shown in the following code:

package main
import "fmt"
func main() { 
  fmt.Println("Hello, World!")
} 

golang.fyi/ch01/helloworld.go

Save the source code in a file called helloworld.go anywhere inside your GOPATH. Then use the following Go command to compile and run the program:

$> go run helloworld.go 
Hello, World!

If all goes well, you should see the message Hello, World! output on your screen. Congratulations, you have just written and executed your first Go program. Now, let us explore the attributes and characteristics ...

Get Learning Go Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.