Have a look at these two simple packages:
package m
const β = 1
package main
import ("m";"fmt")
func main() {
fmt.Println(m.β)
}
I get this error when I try to compile them:
$ GOPATH=`pwd` go run a.go
# command-line-arguments
./a.go:4: cannot refer to unexported name m.β
./a.go:4: undefined: m.β
Why? I tried replacing the β with B in both packages, and it works, but I'm trying to use the proper symbol here. Maybe both packages are using homoglyphs or different encodings for some reason?
The go specifications say that an identifier is exported if
the first character of the identifier's name is a Unicode upper case letter (Unicode class "Lu")
https://golang.org/ref/spec#Exported_identifiers
func main() {
fmt.Println(unicode.IsUpper('β'))
}
returns
false
http://play.golang.org/p/6KxF5-Cq8P
β is lowercase, so it is not exported and can't be used from outside that package.
fmt.Println(unicode.IsLower('β'))
playground
A function , method in an exported package needs to start with an upper case letter. Ran into the same problem yesterday Error in importing custom packages in Go Lang
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With