Book The Go Programming Language
Contains the implementation of the examples in the book. They are all organized by chapter.
Solutions to the exercises included in the book. DD indicates the chapter of the book to which the exercises belong.
All exercises must be run from its folder.
- Run
go run FILE_NAME
- Compile
go build FILE_NAME
- Create a module
go mod init MODULE_NAME
, MODULE_NAME must be unique or the same project name. - Download project dependencies
go mod tidy
%d
decimal integer%x
,%o
,%b
integer in hexadecimal, octal, binary%f
,%g
,%e
floating-point number%t
boolean%c
rune (Unicode code point)%s
string%q
quoted string%v
any value in a natural format%T
type of any value%%
literal percent sign (no operand)
var name type = expression
- Omit type,
var name = expression
. Type is determinated by the initializer expression. - Omit expression,
var name type
. Initial value is:- 0 for numbers.
- false for booleans.
- "" for strings.
- nil for interfaces, reference types (slice, pointer, map, channel, function).
- Declaration of multile variables:
var i, j, k int
var b, f, s = true, "Hello", 3.98
. bool, string, float64
name := expression
A pointer values is the address of a variable. Example:
x := 1
p := &x // p, of type *int, points to x
fmt.Println(*p) // 1
*p = 2 // equivalent to x = 2
fmt.Println(x) // 2
- Signed integers:
int8, int16, int32 and int32
orint
- Unsigned integers:
uint8, uint16, uint32 and uint32
oruint
rune
is a synonym for int32byte
is a synonym for uint8uintptr
type is used only for low-level programming
* / % << >> & &^
+ - | ^
== != < <= > >=
&&
||
&
, bitwise AND|
, bitwise OR^
, bitwise XOR&^
, bit clear (AND NOT)<<
, left shift>>
, right shift
float32 and float64