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)
}
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容