美文网首页
golang pass var across package

golang pass var across package

作者: RoyTien | 来源:发表于2017-12-08 11:27 被阅读31次

https://golang.org/ref/spec#Exported_identifiers

An identifier may be exported to permit access to it from another package. An identifier is exported if both:

  1. the first character of the identifier's name is a Unicode upper case letter (Unicode class "Lu"); and
  2. the identifier is declared in the package block or it is a field name or method name.

All other identifiers are not exported.

应用const,并且var 的名字第一个字符必须为大写 「capital letter」

package foo
const VarPassed int64 = 12

使用包名+变量名

package main
import(
  f "fmt"
  "library/foo"

func main() {
  f.Println(foo.VarPassed)
}

相关文章

网友评论

      本文标题:golang pass var across package

      本文链接:https://www.haomeiwen.com/subject/xyadvxtx.html