golang pass var across package

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)