当前位置:网站首页>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 .
边栏推荐
- Random talk about redis source code 91
- Hugo 博客搭建教程
- Eve-ng installation (network device simulator)
- Can tonghuashun open an account? Can tonghuashun directly open the security of securities companies on the app
- To understand Devops, you must read these ten books!
- MySQL - > > symbol usage JSON related
- The difference between user status and system status in CRM
- Solution to the problem that the anaconda navigator card logo cannot be opened and the card will flash back - replace the alicloud image source
- 快速复制浏览器F12中的请求到Postman/或者生成相关语言的对应代码
- USB to serial port - maximum peak serial port baud rate vs maximum continuous communication baud rate
猜你喜欢

Write a select based concurrent server

When openharmony meets openeuler

Gospel of audio and video developers, rapid integration of AI dubbing capability

VirtualLab基础实验教程-6.闪耀光栅

Title 37: sorting 10 numbers

Typescript common types (I)

Review of MySQL (3): query operation

js求斐波那契数列

Common methods and examples of defect detection based on Halcon

The difference between user status and system status in CRM
随机推荐
GD32F4xx 与符合DLT645的电能表通信_2
Random talk about redis source code 91
Strings in JS (including leetcode examples) < continuous update ~>
Can tonghuashun open an account? Can tonghuashun directly open the security of securities companies on the app
JS judge palindromes
Title 68: there are n integers, so that the previous numbers are moved backward m positions, and the last m numbers become the first m numbers
General differences between SQL server versions released by Microsoft in different periods so far, for reference
Introduction to reinforcement learning and analysis of classic items 1.3
Topic 66: input array, exchange the largest element with the first element, exchange the smallest element with the last element, and output array.
leetcode 300. Longest increasing subsequence
Title 37: sorting 10 numbers
间隔两个月,我的第二次上榜纪念日【2022.6.2】
用一个性能提升了666倍的小案例说明在TiDB中正确使用索引的重要性
MySQL advanced learning notes
Machine learning series (3): logistic regression
GD32F4xx控制DGUS触控按键
Machine learning series (5): Naive Bayes
Why my order by create_ Time ASC becomes order by ASC
美团智能配送系统的运筹优化实战-笔记
Introduction to service grid and istio - continued