Skip to content

Instantly share code, notes, and snippets.

@Integralist
Created May 25, 2021 13:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Integralist/0058659d37c2bf0691cc7bde8c9579c3 to your computer and use it in GitHub Desktop.
Save Integralist/0058659d37c2bf0691cc7bde8c9579c3 to your computer and use it in GitHub Desktop.
[Go nested struct embedding] #go #golang #struct #embed
package main
import (
"fmt"
)
type Optional struct {
WasSet bool
}
type OptionalString struct {
Optional
Value string
}
type OptionalFoo struct {
OptionalString
}
func main() {
var o OptionalFoo
o.WasSet = true
// The following two field lookups are identical
fmt.Printf("%+v\n", o.WasSet)
fmt.Printf("%+v\n", o.OptionalString.Optional.WasSet)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment