overflow_discovery/api/module/discovery/model/zone.go
crusader 2e81139374 ing
2017-11-22 14:55:40 +09:00

34 lines
547 B
Go

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]
}