当前位置:网站首页>GO语言-init()函数-包初始化
GO语言-init()函数-包初始化
2022-06-24 13:03:00 【一边学习一边哭】
init函数和主函数的异同
- init() main()都是go语言中的保留函数。由go程序自动调用,不可以手动调用。
- init()函数的定义和主函数类似,不能有参数和返回值。init()函数会在主函数执行前执行。
- init()函数可以定义在任意包中,且可以重复定义多个。主函数只能在main包下,且只能有一个。
- 一个package可以被其他的包导入多次,但是初始化只能执行一次。
我们可以在代码中定义init()函数。此函数会在包被导入时执行。
例如。如果实在main中导入包,包中存在init()函数,那么init()中的代码会在main()函数执行前执行,用于初始化包所需要的特定资料。
init()函数执行顺序
- 在同一个包中,init()函数时从上到下运行。
- 在同一个package的不同go文件中,init()函数是根据go文件名的字符串进行排序。
- 不同的package中,如果不互相依赖的话,根据import顺序执行init()函数。
- 如果package存在依赖,init()函数调用顺序为:最后被依赖的包,最先执行。
边栏推荐
- Linux 安装 CenOS7 MySQL - 8.0.26
- 09_一种比较高效的记忆方法
- 港股上市公司公告 API 数据接口
- 10_ Those high-profile personal signatures
- 2022 coal mine gas drainage operation certificate examination questions and simulation examination
- Jericho turns on shouting in all modes to increase mic automatic mute [chapter]
- [R language data science] (XIV): random variables and basic statistics
- 90% of the project managers have skipped the pit. Are you still in the pit?
- 2022 construction elevator driver (construction special type of work) examination questions and online simulation examination
- 食品饮料行业渠道商管理系统解决方案:实现渠道数字化营销布局
猜你喜欢

Rasa 3. X learning series - it is a great honor to be a source code contributor of Rasa contributors, and to build and share the rasa community with rasa source code contributors all over the world!

Télétravail: Camping à la maison gadgets de bureau | rédaction communautaire

Digital business cloud: strengthen supplier management and promote efficient collaboration between air transport enterprises and suppliers

业务与技术双向结合构建银行数据安全管理体系

如何避免下重复订单
![Generate binary tree according to preorder & inorder traversal [partition / generation / splicing of left subtree | root | right subtree]](/img/f7/8d026c0e4435fc8fd7a63616b4554d.png)
Generate binary tree according to preorder & inorder traversal [partition / generation / splicing of left subtree | root | right subtree]

鲲鹏arm服务器编译安装PaddlePaddle

P2pdb white paper

OpenHarmony 1

leetcode:1504. Count the number of all 1 sub rectangles
随机推荐
[deep learning] storage form of nchw, nhwc and chwn format data
leetcode:1504. 统计全 1 子矩形的个数
Kunpeng arm server compilation and installation paddlepaddle
日常知识科普
Jericho turns on shouting in all modes to increase mic automatic mute [chapter]
厨卫电器行业B2B交易协同管理平台开发,优化企业库存结构
业务与技术双向结合构建银行数据安全管理体系
Generate binary tree according to preorder & inorder traversal [partition / generation / splicing of left subtree | root | right subtree]
Harmony os. (2)
Defoaming
`Thymeleaf`模板引擎全面解析
Mit-6.824-lab4a-2022 (ten thousand words explanation - code construction)
Autorf: learn the radiation field of 3D objects from single view (CVPR 2022)
ASCII code table extracted from tanhaoqiang's C program design (comparison table of common characters and ASCII codes)
AntD checkbox,限制选中数量
【环境搭建】zip 分卷压缩
The function and principle of key in V-for
Unit contour creation method
One click to generate University, major and even admission probability. Is it so magical for AI to fill in volunteer cards?
win10系统问题