Selectors
…
A selector
f
may denote a field or methodf
of a typeT
, or it may refer to a field or methodf
of a nested embedded field ofT
. The number of embedded fields traversed to reachf
is called its depth inT
. The depth of a field or methodf
declared inT
is zero. The depth of a field or methodf
declared in an embedded fieldA
inT
is the depth off
inA
plus one.
The importance of this concept of depth will become apparent in our next installment, but for now let’s look at some examples, just to make this crystal clear.
type Person struct {
Name string
}
type Employee struct {
Person
JobTitle string
}
var e Employee
e.JobTitle // JobTitle's depth is zero
e.Name // Name's depth is 1
e.Person // Person's depth is 1
Quotes from The Go Programming Language Specification Version of August 2, 2023