I have the following struct:
type Foo struct {
Bar *FooBar
Baz *FooBaz
}
type FooBar struct {
Name string
}
type FooBaz struct {
Name string
}
How can I access the Baz
and Bar
in the struct without getting a nil pointer reference when they're not set?
I want something that goes like the below, but I keep getting nil pointer dereference errors.
if Foo.Bar == nil {
throw error
}
I'm struggling with this!