Building Code Samples

The code samples in this tutorial can be built and run on your computer, all you need is a working Go installation.

Once you have Go installed you can copy any example (use the “Copy Code” button) and paste it into a text file. Save the file with “.go” extension, such as “hello.go”. You can then run the file directly using “go run” on the command line:

go run hello.go

This command will run the application from your computer. For simple go programs this will output some information to your command line. However most examples in this tour will open a new window on your computer!

They can also be built as applications to run later using the “go build” command;

go build hello.go

This will create an executable file that can be run any number of times.

Example Code

1
2
3
4
5
6
7
package main

import "fmt"

func main() {
	fmt.Println("I am running on your computer")
}