Selectors
…
A selector
fmay denote a field or methodfof a typeT, or it may refer to a field or methodfof a nested embedded field ofT. The number of embedded fields traversed to reachfis called its depth inT. The depth of a field or methodfdeclared inTis zero. The depth of a field or methodfdeclared in an embedded fieldAinTis the depth offinAplus 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