当前位置:网站首页>Go init initialization function
Go init initialization function
2022-06-12 18:35:00 【Foxconn quality inspector zhangquandan】
main Bag and init function
init Function is used to initialize the package , No return value , No parameter . It is recommended that only one... Be defined for each package .init Function in import

_ Used for initialization import

You can see main There's nothing in it , But it printed init The statement in the function .
Load when the program is executing main package ,main And then load other , stay main It loads programs from top to bottom , Load the program first , When loading the program, I found import 了 , This is the time to find import Package and load .
When the package is found for loading, it will be loaded from top to bottom , If there is import Then you will load other . Because there are many under a bag go file , So these files will be loaded when loading . After loading, you will see what is available init function , Then carry out all the init function , Execute all init So the first one import The import is complete .

import After that, it will be executed main Function loading , If main There are also init Function, then execute it first init Function initialization , It will not be executed until the execution is completed main function .( A package can contain multiple init function )
If there are more than one under a package go file , There's... In it init This function , So the order of execution is random .
init It can be used later when it is related to the database , Initialize the connection , This is also the principle of initializing some drivers .
There are many more packages that use underscores _ To import , In fact, it is to execute the init function .
边栏推荐
- 用一个性能提升了666倍的小案例说明在TiDB中正确使用索引的重要性
- leetcode 647. Palindrome substring
- SCI Writing - Results
- 间隔两个月,我的第二次上榜纪念日【2022.6.2】
- Title 54: take 4 ~ 7 bits of an integer a from the right end.
- js二分法
- js判断回文数
- VirtualLab基础实验教程-4.单缝衍射
- Typescript type declaration file (III)
- Solution to the problem that the anaconda navigator card logo cannot be opened and the card will flash back - replace the alicloud image source
猜你喜欢

Title 37: sorting 10 numbers

Gd32f4xx controls dgus variable display

Typescript common types (I)

Review of MySQL (I): go deep into MySQL

VirtualLab基础实验教程-4.单缝衍射

迄今微软不同时期发布的SQL Server各版本之间的大致区别,供参考查阅

Solution to the problem that the anaconda navigator card logo cannot be opened and the card will flash back - replace the alicloud image source

【sql语句基础】——查(select)(单表查询)

Review of MySQL (VIII): Transactions

Introduction to reinforcement learning and analysis of classic items 1.3
随机推荐
Review of MySQL (V): Joint table query and sub query
Typescript advanced type (2)
Is it safe to open an account in flush
lua记录
Two months later, my second listing anniversary [June 2, 2022]
309. the best time to buy and sell stocks includes the freezing period
Problems that the sap Spartacus e-commerce cloud UI shipping method does not display in the unit test environment
Gospel of audio and video developers, rapid integration of AI dubbing capability
快速复制浏览器F12中的请求到Postman/或者生成相关语言的对应代码
Why my order by create_ Time ASC becomes order by ASC
笔记本电脑清灰打硅脂后,开机一直黑屏,如何破?
用grep awk提取字符串
基于STM32设计智能家居控制系统(OneNet)_2022
Self made calculator (1 realized by Boolean logic operation unit and control unit programming)
每日一博 - 微服务权限一二事
Review of MySQL (I): go deep into MySQL
When openharmony meets openeuler
01 complexity
JS quick sort
Gd32f4xx controls dgus variable display