开始-获取父结构

I'd like to know how to retrieve the parent struct of an instance.
I have no idea how to implement this.

For instance:

type Hood struct {
    name string
    houses  []House
}

type House struct {
    name   string
    people int16
}

func (h *Hood) addHouse(house House) []House {
    h.houses = append(h.houses, house)
    return h.houses
}

func (house *House) GetHood() Hood {
    //Get hood where the house is situated
    return ...?
}

Cheers

You should retain a pointer to the hood.

type House struct {
    hood   *Hood
    name   string
    people int16
}

and when you append the house

func (h *Hood) addHouse(house House) []House {
    house.hood = h
    h.houses = append(h.houses, house)
    return h.houses
}

then you can easily change the GetHood, although a getter may not be required at that point.

func (house *House) GetHood() Hood {
    return *house.hood
}