当前位置:网站首页>Go language self-study series | golang init function
Go language self-study series | golang init function
2022-04-21 22:52:00 【COCOgsta】
Video source :B standing 《golang Introduction to project practice [2021 newest Go Language course , There is no nonsense , Dry only ! Ongoing update ...]》
Organize the teacher's course content and test notes while studying , And share it with you , Infringement is deleted , Thank you for your support !
Attach summary sticker :Go Language self-study series | Summary _COCOgsta The blog of -CSDN Blog
golang There is a special function init function , Precede main Function execution , Implement some initialization operations at the package level .
init The main characteristics of function
- init Function precedes main Function automatic execution , Cannot be called by other functions
- init Function has no input parameters 、 Return value
- Each bag can have more than one init function
- Each source file of a package can also have multiple init function , This is special
- Of the same package init Execution order ,golang There is no clear definition , When programming, be careful that the program does not rely on this execution order
- Different packages init The function determines the execution order according to the dependency of package import
golang Initialization sequence
Initialization sequence : Variable initialization ->init()->main()
example
package main
import "fmt"
var i int = initVar()
func init() {
fmt.Println("init2")
}
func init() {
fmt.Println("init...")
}
func initVar() int {
fmt.Println("initVar...")
return 100
}
func main() {
fmt.Println("main....")
}
Running results
[Running] go run "d:\SynologyDrive\ software development \go\golang Introduction to project practice \goproject\360duote.com\pro01\test.go"
initVar...
init2
init...
main....
版权声明
本文为[COCOgsta]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204212034376020.html
边栏推荐
- Pyqt5 + opencv operate local camera
- APM (application performance monitoring) industry Cognition Series - I
- 2022 intermediate accounting title examination economic law practice questions and answers
- Is it safe to open futures account on mobile phone? Do you need to handle it offline?
- After learning the linked list, don't you find some classic examples to consolidate your knowledge? The five OJ classic examples of the linked list, can you? Let's have a look (knowledge analysis + gr
- YARN线上动态资源调优
- Kubenetes (3) -- network communication (2) -- flannel and calico
- CDGA敏捷开发的12个原则在企业数据治理中的应用
- [Central South University of forestry science and technology] [Chen] sixth week innovation question prime
- Sorting methods (8 kinds) detailed explanation 6 - quick sorting
猜你喜欢

Outsourcing student management system detailed architecture design document

Reproduce the pathways language model using colossal AI

【FPGA的基础学习-------OV7725摄像头模块】

Kubenetes(3)--网络通信(2)--flannel和calico

PyQt5+OpenCV操作本地摄像头

Database exercise

Oracle database 22c insight:_ kgl_ Large_ heap_ assert_ Threshold automatic and manual adjustment

Kubernetes---ConfigMap配置管理

MySQL multi table query exercise

Dynamic programming: complete knapsack problem
随机推荐
Deploying wikijs using Helm
[sdoi2012] Chandelier
POI Point of interesting.
7.2.3 multiple representations of posture, quaternion, Euler angle, rotation matrix and axis angle ros2 in hands on Robotics
L1-057 PTA refreshed me (5 points)
Cleaning robot - infrared down looking sensor to detect whether there is a sudden change in ground distance
Cyclic queue and capacity expansion
[MQ] starting from scratch to realize mq-01-start of producers and consumers
[summary of some tips and shortcut keys in MATLAB]
[pytorch] common functions
OS Experiment 3 [process communication]
Nacos Registry - service registration and tiered storage
2、Failed to connect to MySQL Server 8.0.28 after 10 attempts
将模型训练外包真的安全吗?新研究:外包商可能植入后门,控制银行放款
2022 Intermediate Accounting Title Financial Management exercises and answers
P1027 [noip2001 improvement group] car's travel route (the shortest path in the diagram)
MySQL 第3章 SQL基础语法
Why is everything console I can't come out. console. log(depsMap)
Event distribution mechanism Android, Android interview summary of large manufacturers, detailed answers
【ACM】46. 全排列(1. 这里需要用到前面的元素进行排列,故不用startindex(组合、分割时才用);2. 注意处理数组中元素是否重复使用的问题(使用contains函数))