隐式私有函数导入?

huangapple go评论72阅读模式
英文:

Implicit private function import?

问题

main.go是如何使用buildIndexMapping函数的呢?

这个函数没有大写字母开头,所以它如何在包内公开访问,而且还没有显式导入mapping.go

main.go: https://github.com/blevesearch/beer-search/blob/721fab2198a52d919133df08058fde8043bab365/main.go#L55

mapping.go: https://github.com/blevesearch/beer-search/blob/721fab2198a52d919133df08058fde8043bab365/mapping.go#L19

英文:

How is main.go able to use buildIndexMapping?

The function is not uppercased so how is it publicly accessible within the package and that too without an explicit import of mapping.go?

main.go: https://github.com/blevesearch/beer-search/blob/721fab2198a52d919133df08058fde8043bab365/main.go#L55

mapping.go: https://github.com/blevesearch/beer-search/blob/721fab2198a52d919133df08058fde8043bab365/mapping.go#L19

答案1

得分: 2

两者都在同一个包中。在Go语言中,你导入的是包,而不是文件,因此私有函数是可用的。

英文:

Both are in the same package. In Go you import packages, not files, thus the private function is available.

huangapple
  • 本文由 发表于 2015年7月11日 14:46:59
  • 转载请务必保留本文链接:https://go.coder-hub.com/31354304.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定