当前位置:网站首页>The difference between underline and dot of golang import package

The difference between underline and dot of golang import package

2022-04-23 19:21:00 Handsome that handsome

stay golang When importing packages , We sometimes encounter the need to underline or dot the front of the package , I never understood what it meant , Then a search was carried out :

The package is underlined _: When importing a package , All the documents under the package init Functions are executed , But sometimes we just need to use init Function. I don't want to import the whole package into ( Do not use other functions in the package )

Before the bag is a dot .:

import(.“fmt”)
The meaning of this point operation is that after the package is imported, when you call the function of the package , You can omit the prefix package name , That's what you called earlier fmt.Println(“hello world”) It can be written as Println(“hello world”)

版权声明
本文为[Handsome that handsome]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204210557450790.html