Exported names

After importing a package, you can refer to the names it exports.

In Go, a name is exported if it begins with a capital letter.

Foo is an exported name, as is FOO. The name foo is not exported.

Run the code. Then rename math.pi to math.Pi and try it again.\

When two or more consecutive named function parameters share a type, you can omit the type from all but the last.

multiple results Named results

Short variable declarations = vs :=

types: complex64 complex128

Unlike in C, in Go assignment between items of different type requires an explicit conversion. Try removing the float64 or int conversions in the example and see what happens.

Go has only one looping construct, the for loop.

The basic for loop looks as it does in C or Java, except that the ( ) are gone (they are not even optional) and the { } are required. As in C or Java, you can leave the pre and post statements empty. At that point you can drop the semicolons: C’s while is spelled for in Go. If you omit the loop condition it loops forever, so an infinite loop is compactly expressed.

Like for, the if statement can start with a short statement to execute before the condition. Variables declared by the statement are only in scope until the end of the if.

Pointers

Go has pointers, but no pointer arithmetic.

Struct fields can be accessed through a struct pointer. The indirection through the pointer is transparent.

The expression new(T) allocates a zeroed T value and returns a pointer to it.

var t *T = new(T) or

t := new(T)