Hello, World!

Download go eBook

Example

Place the following code into a file name hello.go:

package main

import "fmt"

func main() {
    fmt.Println("Hello, 世界")
}

Playground

When Go is installed correctly this program can be compiled and run like this:

go run hello.go

Output:

Hello, 世界

Once you are happy with the code it can be compiled to an executable by running:

go build hello.go

This will create an executable file appropriate for your operating system in the current directory, which you can then run with the following command:

Linux, OSX, and other Unix-like systems

./hello

Windows

hello.exe

Note: The Chinese characters are important because they demonstrate that Go strings are stored as read-only slices of bytes.

Stats

Contributors: 16
2016-09-12
Licensed under: CC-BY-SA

Not affiliated with Stack Overflow
Rip Tutorial: info@zzzprojects.com

Download eBook