File tree Expand file tree Collapse file tree 5 files changed +10
-55
lines changed Expand file tree Collapse file tree 5 files changed +10
-55
lines changed Original file line number Diff line number Diff line change 4
4
// Package animals provides support for animals.
5
5
package animals
6
6
7
- // Animal represents information about all animals.
8
- type Animal struct {
7
+ // animal represents information about all animals.
8
+ type animal struct {
9
9
Name string
10
10
Age int
11
11
}
12
12
13
13
// Dog represents information about dogs.
14
14
type Dog struct {
15
- Animal
15
+ animal // The embedded type is unexported.
16
16
BarkStrength int
17
17
}
Original file line number Diff line number Diff line change 2
2
// https://github.com/ArdanStudios/gotraining/blob/master/LICENSE
3
3
4
4
// Sample program to show how to create values from exported types with
5
- // embedded types.
5
+ // embedded unexported types.
6
6
package main
7
7
8
8
import (
@@ -13,14 +13,14 @@ import (
13
13
14
14
// main is the entry point for the application.
15
15
func main () {
16
- // Create a value of type Dog from the animals package.
16
+ /// Create a value of type Dog from the animals package.
17
17
dog := animals.Dog {
18
- Animal : animals.Animal {
19
- Name : "Chole" ,
20
- Age : 1 ,
21
- },
22
18
BarkStrength : 10 ,
23
19
}
24
20
21
+ // Set the exported fields from the unexported animal inner type.
22
+ dog .Name = "Chole"
23
+ dog .Age = 1
24
+
25
25
fmt .Printf ("Dog: %#v\n " , dog )
26
26
}
Load Diff This file was deleted.
Load Diff This file was deleted.
Original file line number Diff line number Diff line change @@ -27,9 +27,7 @@ http://www.goinggo.net/2013/08/organizing-code-to-support-go-get.html
27
27
28
28
[ Unexported struct type fields] ( example4/example4.go )
29
29
30
- [ Exported embedded types] ( example5/example5.go )
31
-
32
- [ Unexported embedded types] ( example6/example6.go )
30
+ [ Unexported embedded types] ( example5/example5.go )
33
31
34
32
## Exercises
35
33
You can’t perform that action at this time.
0 commit comments