GolangNote

Golang笔记

golang cannot refer to unexported name

Permalink

出现这个错误的原因你可能想不到

plaintext: unexported
1
2
golang cannot refer to unexported name
不能引用未导出名称

大部分的原因是因为:

plaintext: 修正
1
函数或变量名首字母是小写

Go: 大小写变量名
1
2
3
4
type my struct {
    a   string // 不能在本包外被引用,引用可能会有以上报错
    B  string // 可以在本包外被引用
}

本文网址: https://golangnote.com/topic/127.html 转摘请注明来源

Related articles

Golang 泛型性能初识

编程时,我们通常需要编写“泛型”函数,其中确切的数据类型并不重要。例如,您可能想编写一个简单的函数来对数字进行求和。Go 直到最近才有这个概念,但最近才添加了它(从1.18版开始)。...

Golang 数据库 Bolt 碎片整理

Bolt 是一个优秀、纯 Go 实现、支持 ACID 事务的嵌入式 Key/Value 数据库。但在使用过程中会有很多空间碎片。一般数据库占用的空间是元数据空间的 1.5~4 倍。Bolt 没有内置的压缩功能,需要手动压缩。...

Write a Comment to "golang cannot refer to unexported name"

Submit Comment Login
Based on Golang + fastHTTP + sdb | go1.22.3 Processed in 0ms