- First install go:
brew install go
If you want to check the documentation about the fmt module, you can do the next command:
go doc fmt
go doc fmt.Println
-
VisualStudio Codium The best way is to install Visual Studio Codium and then install the Go extension. After that use CTRL(command) + SHIFT + P to select all of the choices and install them.
-
init go to the folder where you want to initialize your go app and do next command:
go mod init github.com/ognjen-it/go-app
- Declaring Variables: could declare in two or one line:
var i int
i = 42
or
var i int = 42
or leave go to set init/float/string..
i := 42
Const is similar as variable but cannot be reassigned and must be declared in compiling time/
The const cannot be reassign, for example:
const pi = 3.1415
fmt.Println(pi)
pi = 1.2
With const we can set multi const:
const (
first = 1
second = "second"
)
iota - every time we use it then it increases exponentially. For example:
const (
first = iota
second = iota
third // here you can see that third inherit last defined const
)
fmt.Println(first, second, third)
But, if we set new const, then it will be reset:
const (
first = iota
second
)
const (
third = iota
fourth
)
fmt.Println(first, second, third, fourth)