package model import "sync" type Zone struct { ID int `json:"id,omitempty"` Network string `json:"network"` IP string `json:"ip"` Iface string `json:"iface"` Mac string `json:"mac"` hosts map[string]*Host mtx sync.RWMutex } func (z *Zone) AddHost(h *Host) { z.mtx.Lock() defer z.mtx.Unlock() if nil == z.hosts { z.hosts = make(map[string]*Host) } z.hosts[h.IP] = h } func (z *Zone) GetHost(ip string) *Host { z.mtx.RLock() defer z.mtx.RUnlock() if nil == z.hosts { return nil } return z.hosts[ip] }