英文:
How to import go package as underscore "_"?
问题
由于在Go语言中,_
被用作空白标识符以丢弃值。下面的导入语句将导入该包并执行其init
函数。是否有一种方法可以将该包别名为_
,这样我就可以使用_.Method()
来调用它。
import (
_ "github.com/ziutek/mymysql/godrv"
)
英文:
Since _
is used in Go as a blank identifier to discard value. The import statement below will import the package and execute its init
function. Is there a way to alias the package as _
? so that I can use it as _.Method()
.
import (
_ "github.com/ziutek/mymysql/godrv"
)
答案1
得分: 1
不,根据你描述的原因,这是不可能的。最接近的方法是使用两个下划线:
import (
__ "github.com/ziutek/mymysql/godrv"
)
<!-- -->
__.Method()
英文:
No, this is not possible, for the reason you described. The closest you can do is use two underscores:
import (
__ "github.com/ziutek/mymysql/godrv"
)
<!-- -->
__.Method()
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论