Skip to content

Latest commit

 

History

History
81 lines (67 loc) · 1.36 KB

HowTo.md

File metadata and controls

81 lines (67 loc) · 1.36 KB

How to initialize go env

  1. 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
  1. 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.

  2. 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
  1. 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)