Next: Go Packages and the Standard Library, Up: Tutorial [Index]
C is one of the most direct influences on Go, and ‘hello, world’ illustrates
a number of central ideas.
package main
import "fmt"
func main () {
fmt.Println("Hello, world!")
}
Listing 1.1: gopl.io/ch1/helloworld
go commandgo runGo is a compiled language. The Go ‘toolchain’ converts a source program
and the things it depends on into instructions in the native machine language
of a computer. These tools are accessed through a single command called go
that has a number of subcommands. The simplest of these subcommands is run,
which
.go,
$ go run helloworld.go ==> Hello, world!
Go natively handles Unicode, so it can process text in all the world’s languages.
go buildIf the program is more than a one-shot experiment, it’s likely that you would
want to compile it once and save the compiled result for later use. That is
done with go build:
$ go build helloworld.go $ # produces an executable binary file called 'helloworld' $ ./helloworld ==> Hello, world!