Getting Started

If statement

if true { fmt.Println("Yes!") } 

See: Flow control

Comments

// Single line comment /\* Multi- line comment \*/ 

Functions

package main import "fmt" // The entry point of the programs func main() { fmt.Println("Hello world!") say("Hello Go!") } func say(message string) { fmt.Println("You said: ", message) } 

See: Functions

Variables

var s1 string s1 = "Learn Go!" // declare multiple variables at once var b, c int = 1, 2 var d = true 

Short declaration

s1 := "Learn Go!" // string b, c := 1, 2 // int d := true // bool 

See: Basic types

hello.go

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

Run directly

$ go run hello.go Hello, world! 

Or try it out in the Go repl

Comments