Non-Exported Fields

This lesson covers the important concept of how to use fields of a struct if a struct is present in another file or in a separate custom package.

Methods and non-exported fields

How can we change, or even read the name of the object of a user-defined type in another program? This is accomplished using a well-known technique from OO-languages: provide getter and setter methods. For the setter-method, we use the prefix Set, and for the getter-method, we only use the field name.

Look at the example below:

Get hands-on with 1400+ tech skills courses.