Go语言规范-Import Aliasing
生活随笔
收集整理的這篇文章主要介紹了
Go语言规范-Import Aliasing
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
0. 目錄
1. 點(diǎn)操作和_操作
導(dǎo)入包時(shí),我們會(huì)看到如下點(diǎn)操作 和**_操作**:
import (. "xxx/xxx/xxx"_ "xxx/xxx/xxx" )點(diǎn)操作: 可以理解為包名不需要寫了,比如 fmt.Println(“Hello world!”),只要改成 Println(“Hello world!”)。
_操作: 該包內(nèi)的所有 init() 函數(shù)都會(huì)被執(zhí)行,僅希望包內(nèi)的 init() 函數(shù)被執(zhí)行。
2. 導(dǎo)入同名包
我們導(dǎo)入包時(shí)很容易出現(xiàn)同名,那我們?cè)撛趺醋瞿?#xff1f;解決方案如下:
import ("text/template"htemplate "html/template" // this is now imported as htemplate )參考資料:
https://stackoverflow.com/questions/10408646/how-to-import-and-use-different-packages-of-the-same-name
總結(jié)
以上是生活随笔為你收集整理的Go语言规范-Import Aliasing的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: OTB100数据集序列分类
- 下一篇: C++连接CTP接口实现简单量化交易(行