GO programming: exporting functions, structs to other packages

Categories: Blog

So this is interesting and I found out only after facing the issue, in order to export a function to a different package the function should start with uppercase, and then while trying trying to use a struct from a different package I realize that this is also true for those and any other identifier, and sure enough, you can find that in the language 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.

You can read more about it here.

«
»