赞
踩
预计阅读时间——15分钟
一般来说,我们通常会讲Go程序的入口函数是main,是否还有比main函数更早得到运行的函数呢?
这篇文档就会讲到关于初始化函数init,尽量言简意赅以例子的形式展开。
Finally, each source file can define its own niladic init function to set up whatever state is required. (Actually each file can have multiple init functions.) And finally means finally: init is called after all the variable declarations in the package have evaluated their initializers, and those are evaluated only after all the imported packages have been initialized.
Besides initializations that cannot be expressed as declarations, a common use of init functions is to verify or repair correctness of the program state before real execution begins.
每个模块都可以有一个或者多个init函数,它们的特性和作用是:
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。