32 lines
459 B
Go

package model
import (
"net"
"sync"
"time"
)
type Device struct {
IP string
LastSeen time.Time
StationID string
}
var (
devices = make(map[string]*Device)
deviceMutex sync.RWMutex
)
func RegisterDevice(stationID string, addr net.Addr) {
ip, _, _ := net.SplitHostPort(addr.String())
deviceMutex.Lock()
defer deviceMutex.Unlock()
devices[stationID] = &Device{
IP: ip,
LastSeen: time.Now(),
StationID: stationID,
}
}