Golang Notes

Package

A golang program (executable) has a package name "main". A golang library can has an arbitrary package name. Only one file declaring/implementing the main method can directly resides in the "main" package.

Function and Variable Declaration Style

Golang follows the scala style in that all types are decleared after an identifier and return types are declared after parameter list.

Method Declaration

A method has receiver parmenter placed ahead of method identifier.

Exported Package Members

An exported package member must have an identifier with a capital letter.
This package member will be referenced throught package name.

Variable

There are two types of variables: const and var.

Array Type

The length of an array is part of its type

Multiple Return

Multiple return values of a function can be discarded on the receiving side by assigning it to _ variable.
For statement "range", this "_" variable can be omitted

mime/multipart.File

The Read method of object with type: mime/multipart.File can only be used effectively once. When called on the same object the second time, no data will be read from the File.

Relative File Path

For io operations, relative file path are relative to the current working directory.

nil value

nil is the zero value for pointers, interfaces, maps, slices, channels and function types, representing an uninitialized value. nil error means no error