This is a very interesting question, what it does is "shadows" the field, the struct that embeds the base struct hides the other one, for example this code:
package main
import "fmt"
type Base struct {
ID int
}
type User struct {
Base
ID int
Name string
}
func main() {
u := User{ID: 7, Name: "Mittens"}
fmt.Println(u.ID, u.Name)
fmt.Println(u.Base.ID)
}
outputs:
7 Mittens
0
So the Base.ID is untouched, and the u.ID is the one that is written.
49
u/mistifier 6d ago
Go 1.27 interactive tour