当前位置:网站首页>Go language -init() function - package initialization
Go language -init() function - package initialization
2022-06-24 14:21:00 【Crying while learning】
init Similarities and differences between function and main function
- init() main() All are go Reserved functions in language . from go Program calls automatically , Cannot be called manually .
- init() The definition of the function is similar to that of the main function , Parameters cannot have and return values .init() The function executes before the main function executes .
- init() Functions can be defined in any package , And multiple... Can be defined repeatedly . The main function can only be used in main It's a bag , And only one .
- One package Can be imported multiple times by other packages , But initialization can only be performed once .
We can define it in the code init() function . This function will execute when the package is imported .
for example . If it's true main Import package from , There is... In the package init() function , that init() The code in will be in main() Execute before function execution , Used to initialize the specific data required by the package .
init() Function execution order
- In the same package ,init() Function from top to bottom .
- In the same package Different go In file ,init() The function is based on go Sort the string of file name .
- Different package in , If we don't depend on each other , according to import Sequential execution init() function .
- If package There is dependence ,init() The order of function calls is : The last package to be relied on , The first to perform .
边栏推荐
- 智慧园区SaaS管理系统解决方案:赋能园区实现信息化、数字化管理
- js去除字符串空格
- Research on MySQL composite index
- SAP Marketing Cloud 功能概述(四)
- Go语言三个高效编程的技巧
- In the eyes of the universe, how to correctly care about counting East and West?
- Zhiyuan community weekly 86: Gary Marcus talks about three linguistic factors that can be used for reference in large model research; Google puts forward the Wensheng graph model parti which is compar
- Jerry's infrared filtering [chapter]
- [environment setup] zip volume compression
- 根据前序&中序遍历生成二叉树[左子树|根|右子树的划分/生成/拼接问题]
猜你喜欢

unity 等高线创建方法

MySQL复合索引探究
![Jerrys timer0 uses the default pa13 to detect the pulse width [chapter]](/img/4e/de0951c8be5ddd765b15b773c04fa7.png)
Jerrys timer0 uses the default pa13 to detect the pulse width [chapter]

ASCII code table extracted from tanhaoqiang's C program design (comparison table of common characters and ASCII codes)

leetcode:1504. 统计全 1 子矩形的个数

远程办公之:在家露营办公小工具| 社区征文

Linux 安装 CenOS7 MySQL - 8.0.26

Three efficient programming skills of go language

数商云:加强供应商管理,助推航空运输企业与供应商高效协同

不要小看了积分商城,它的作用可以很大
随机推荐
In the eyes of the universe, how to correctly care about counting East and West?
PgSQL queries the largest or smallest data of a field in a group
融云通信“三板斧”,“砍”到了银行的心坎上
AntD checkbox,限制选中数量
Database considerations
Mit-6.824-lab4a-2022 (ten thousand words explanation - code construction)
Common singleton mode & simple factory
OpenHarmony 1
Unit contour creation method
数字臧品系统开发 NFT数字臧品系统异常处理源码分享
MySQL日志管理、备份与恢复
4个不可不知的“安全左移”的理由
Redis interview questions
Halcon 绘制区域 到图片中
conda和pip命令
Jericho After sleep, the system will wake up regularly and continue to run without resetting [chapter]
Method of establishing unity thermodynamic diagram
Common sense knowledge points
SaaS management system solution of smart Park: enabling the park to realize information and digital management
GO语言-init()函数-包初始化