Skip to content

Commit 76df812

Browse files
Fixed typos
1 parent c74979a commit 76df812

4 files changed

Lines changed: 42 additions & 2 deletions

File tree

chapter5/listing66/counters/counters.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ package counters
55
// contains an integer counter for alerts.
66
type 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.
910
func New(value int) alertCounter {
1011
return alertCounter(value)
1112
}

chapter5/listing69/entities/entities.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// people in the system.
33
package entities
44

5-
// User represents a base user.
5+
// User defines a user in the program.
66
type User struct {
77
Name string
88
email string
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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+
}

chapter5/listing72/listing72.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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+
}

0 commit comments

Comments
 (0)