Entry Point
Main package
Пакет main является специальным пакетом и может иметь свое имя вне зависит от имени содержащей его директории.
mainpackage is the entry-point package for executable programs.Programs start running function
main()in packagemain.Library packages are only reusable packages and don’t contain main package, and an entry-point (mostly).
If your
mainfunction doesn’t exist in packagemain, the build tools won’t produce an executable.Main packages are not importable packages and you don’t need to export things from main package.
Init function
init - это специальная функция, выполняющая до main с целью установки значения пакета:
Function
initis executed beforemain.Each source file can define its own
initfunction to set up whatever state is required.Each file can have multiple
initfunctions.При первом импорте пакета в первый раз будут выполнены все его
initфункции.Никакой порядок не гарантируется при выполнении
initфункций.initis called after all the variable declarations in the package have evaluated their initialisers, and those are evaluated only after all the imported packages have been initialised.
Last updated
Was this helpful?