2017-11-15 10:38:42 +00:00
|
|
|
package model
|
|
|
|
|
2017-11-22 05:55:40 +00:00
|
|
|
import "sync"
|
|
|
|
|
2017-11-15 10:38:42 +00:00
|
|
|
type Zone struct {
|
|
|
|
ID int `json:"id,omitempty"`
|
|
|
|
Network string `json:"network"`
|
|
|
|
IP string `json:"ip"`
|
|
|
|
Iface string `json:"iface"`
|
|
|
|
Mac string `json:"mac"`
|
2017-11-22 05:55:40 +00:00
|
|
|
|
2017-11-23 09:34:07 +00:00
|
|
|
hosts map[string]*Host `json:"-"`
|
|
|
|
mtx sync.RWMutex `json:"-"`
|
2017-11-22 05:55:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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]
|
2017-11-15 10:38:42 +00:00
|
|
|
}
|