Notes About Go (part 1)
This is - probably - a series of short notes about Go during my learning journey. There might be some errors and things I got wrong here and there that I maybe fix later during my learning journey or maybe I don’t.
Variables
| := | Deceleration (first time) |
| = | Assignment |
Note: Short deceleration := can assign variables too BUT has to declare 1 new variables at least. For example:
// Correct
in, err := o.Open(file)
out, err := o.Create(file)
// Wrong (won't compile)
in, err := o.Open(file)
in, err := o.Create(file)
Scope
Go Routines
-
Create a channel
ch := make(chan String) - Call a function with
goprefixed and pass the channel variable as an argument.go myFunc(ch) -
To receive output from a channel you can do something like:
fmt.Println(<- ch) -
To send things to the channel using you can do something like:
ch <- "String
fmt
Printf variables referencing and octal numbers:
o := 0700 // Octal numbers can be defined with `0` prefixed
fmt.Printf("%d %[1]o %#[1]o", o) // 448 700 0700