File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -5,7 +5,8 @@ package counters
55// contains an integer counter for alerts.
66type alertCounter int
77
8- // New creates and returns objects of the unexported type alertCounter.
8+ // New creates and returns values of the unexported
9+ // type alertCounter.
910func New (value int ) alertCounter {
1011 return alertCounter (value )
1112}
Original file line number Diff line number Diff line change 22// people in the system.
33package entities
44
5- // User represents a base user.
5+ // User defines a user in the program .
66type User struct {
77 Name string
88 email string
Original file line number Diff line number Diff line change 1+ // Package entities contains support for types of
2+ // people in the system.
3+ package entities
4+
5+ // user defines a user in the program.
6+ type user struct {
7+ Name string
8+ Email string
9+ }
10+
11+ // Admin defines an admin in the program.
12+ type Admin struct {
13+ user // The embedded type is unexported.
14+ Rights int
15+ }
Original file line number Diff line number Diff line change 1+ // Sample program to show how unexported fields from an exported
2+ // struct type can't be accessed directly.
3+ package main
4+
5+ import (
6+ "fmt"
7+
8+ "github.com/goinaction/code/chapter5/listing72/entities"
9+ )
10+
11+ // main is the entry point for the application.
12+ func main () {
13+ // Create a value of type Admin from the entities package.
14+ a := entities.Admin {
15+ Rights : 10 ,
16+ }
17+
18+ // Set the exported fields from the unexported
19+ // inner type.
20+ a .Name = "Bill"
21+ a .Email = "bill@email.com"
22+
23+ fmt .Printf ("User: %v\n " , a )
24+ }
You can’t perform that action at this time.
0 commit comments