FreeCodeCamp.org https://www.youtube.com/watch?v=YS4e4q9oBaU
Go (golang) - golang.org
- Strong and statically typed
- Excellent community
- Key features
- Simplicity
- Fast compile times
- Garbage collected (still you can manage your memory)
- Built-in concurrency
- Compile to standalone binaries
- Variable declaration
var foo int
var foo int = 42
foo := 42
-
Can't redeclare variables, but can shadow them
-
All variables must be used
-
Visibility
- lower case first letter for package scope
- upper case first letter to export
- no private scope
-
Naming conventions
- HighCamelCase or lowerCamelCase
- Capitalize acronyms (HTTP, URL)
-
Type conversion
- destinationType (variable)
- use
strconv
package for strings - no implicit type conversion in Go
Exporting to .bashrc, .zshrc, etc.
export GOROOT=/usr/local/go
export PATH=$PATH:$GOROOT/bin
# Create this folder
export GOPATH=$HOME/golib
export PATH=$PATH:$GOPATH/bin
go get github.com/nsf/gocode
- Numeric types
- Integers
- Signed Integers
int
type has varying size, but min 32 bitsint8
throughint64
- Unsigned integers
- 8 bit (
byte
oruint8
) throughuint32
- 8 bit (
- Arithmetic operations
- Addition, subtraction, multiplication, division, remainder
- Bitwise operations
- and (
&
) or (|
), xor(^
), and not (&^
)
- and (
- Zero value is 0
- Can't mix types in same family (e.g.
uint16
+uint32
= error) - Floating points numbers
- Follows IEEE-754 standard
- Zero value is 0
- 32 and 64 bit versions
- Literal styles
- Decimal (3.14)
- Exponential (13e18 or 2E10)
- Mixed (13.7e12)
- Arithmetic operations
- Addition, subtraction, multiplication, division
- Complex numbers
- Zero value is (0+0i)
- 64 and 128 bit versions
- Built-in functions
complex
- make complex number from two floatsreal
- get real part as floatimag
- get imaginary part as float
- Arithmetic operations
- Addition, subtraction, multiplication, division
- Text types
- Strings
- UTF-8
- Immutable
- Can be concatenated with plus (
+
) operator - Can be converted to []byte
- Rune
- UTF-32
- Alias for
int32
- Special methods normally required to process
- e.g.
strings.Reader#ReadRune
- e.g.
- Strings
- Integers