To extend a struct with a new field in Go, you can use embedding. By embedding a struct within another struct, the fields of the embedded struct become part of the embedding struct.
main.go108 chars10 lines
In the above example, the Employee struct embeds the Person struct. This means that Employee struct now has all of the fields of the Person struct in addition to its own fields.
You can now create instances of the Employee struct and access the fields of the Person struct using dot notation:
main.go234 chars12 lines
In this way, you can extend a struct with a new field in Go by embedding another struct within it.
gistlibby LogSnag