Cannot refer to unexported name and undefined Error in Go

Are you facing unexported and undefined errors in Go programming language like the following ?

Unexported name error:

Let us say you have the following project structure and facing the above error while importing custom packages and using functions in that package

Note: Identifier Access

One of the important feature that you need to know in Go language is to use an uppercase or lowercase letter as a first letter when we name a type or variable or function so that the identifier would be public and any code in any package could use it.

If the first letter is lowercase, then the identifier is private and could only accessed within the package where it is declared.

Solution for Unexported name and Undefined Error:
  • You should make your function exportable with an uppercase like  func GetResponseResty()  instead of func getResponseResty() .
  • And call the function like  goresty.GetResponseResty()  in the  main.go  in the main function.

Leave a Reply

1 Comment threads
0 Thread replies
Most reacted comment
Hottest comment thread
1 Comment authors
Luella James Recent comment authors
newest oldest most voted
Notify of
Luella James
Luella James

Good Stuff. This is really a tremendous website.