Lehirt / no_idea

0 stars 0 forks source link

init functions in Go #1

Open Lehirt opened 2 years ago

Lehirt commented 2 years ago

Identifier main is ubiquitous. Every Go program starts in a package main by calling identically named function. When this function returns the program ends its execution. Functions init also play special role.

init functions are defined in package block and are used for:

Package initialization is done only once even if package is imported many times.

Lehirt commented 2 years ago

init函数的主要作用:

init函数的主要特点:

Lehirt commented 2 years ago

引用: https://medium.com/golangspec/init-functions-in-go-eac191b3860a https://zhuanlan.zhihu.com/p/34211611 https://zhuanlan.zhihu.com/p/88128042