Identifier main is ubiquitous. Every Go program starts in a package main by calling identically named function. When this function returns the program ends its execution. Functions init also play special role.
init functions are defined in package block and are used for:
variables initialization if cannot be done in initialization expression,
checking / fixing program’s state,
registering,
running one-time computations,
and many more.
Package initialization is done only once even if package is imported many times.
Identifier main is ubiquitous. Every Go program starts in a package main by calling identically named function. When this function returns the program ends its execution. Functions init also play special role.
init functions are defined in package block and are used for: