Folders and files Name Name Last commit message
Last commit date
parent directory
View all files
break
case
chan
const
continue
default
defer
else
fallthrough
for
func
go
goto
if
import
interface
map
package
range
return
select
struct
switch
type
var
int
int8
int16
int32
int64
unit
unit8
unit16
unit32
uint64
uintptr
float32
float64
complex128
complex64
bool
byte
rune
string
error
make
len
cap
new
append
copy
close
delete
complex
real
imag
panic
recover
There are no uninitialized variables (no assignment defaults to zero-value).
Note do not confuse short, multi-variable declarations with tuple assignments (:=
vs =
)
Short multi-variable assignments will assign to variables already declared. (scope is important)
but a short variable dec must have at least one declaration for this to work.
so just use ordinary assignment (=
) if no new declarations
Style: avoid tuple assignments if complicated expressions/hinders readability
Pointers and addresses (* and &) same as in C lang. Except cannot do pointer arithmetic.
Package-level variable lifetime is entire execution of program
Local variables have dynamic lifetimes: new instance is created each time declaration statement is executed and lives until out of scope/unreachable
Map lookup: v, ok = m[key]
Type assertion: v, ok = x.(T)
Channel receive: v, ok = <-ch
Assignability and comparisons vary by type.
type declarations: type name underlying-type
Each package serves as a separate name space for its declaration.
Exported (public) identifiers start with uppercase letter.
Doc comments are placed immediately before package declarations.
By convention, import name should match the leaf of import path.
Package-level variables are initialized in order they were declared in (note package names sorted before compiling)
Packages resolve dependencies before importing. (if p imports q, q must be fully resolved first).
init
functions in packages are executed when the program starts. Thus, all packages init functions are run before main
.
Lexical blocks ({}
)
Style: handle error in if block, so successful execution path is not indented.
You can’t perform that action at this time.