Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Bind ¶
type Bind struct {
ID string `json:"-"`
IP net.IP `json:"ip"`
ClientMac string `json:"client_mac"`
DeviceMac string `json:"device_mac"`
Port int `json:"port"`
}
Bind links a client to a device port, or just to an IP/MAC for sources without devices (e.g. smart). ID is the record key in the external source.
type BindEvent ¶
type BindEvent struct {
DBType string `json:"db_type"`
Action string `json:"action"`
Object BindEventObject `json:"object"`
}
BindEvent is a single-record change published to Redis by the external system:
{"db_type":"clients","action":"delete","object":{"id":123}}
{"db_type":"clients","action":"add","object":{"id":123,"ip":16909060,"mac":"AABBCCDDEEFF","device_mac":"AABBCCDDEEFF","port":44}}
db_type is a key of Config.Binds. "add" and "update" both upsert by id; device_mac and port are optional.
type BindEventObject ¶
type Config ¶
type Config struct {
DevicesURL string `yaml:"devices_url"`
Binds map[string]string `yaml:"binds"`
RefreshInterval time.Duration `yaml:"refresh_interval"`
Timeout time.Duration `yaml:"timeout"`
Redis RedisConfig `yaml:"redis"`
}
Config describes where to load devices and named bind sources (e.g. clients, smart) from. Redis is optional and delivers per-record updates between reloads.
type Device ¶
type Device struct {
IP net.IP `json:"ip"`
Mac string `json:"mac"`
ParseType string `json:"parse_type"`
}
json tags name the fields as scripts see them.
type RedisConfig ¶
type RedisConfig struct {
Addr string `yaml:"addr"`
Password string `yaml:"password"`
DB int `yaml:"db"`
Channel string `yaml:"channel"`
}
RedisConfig enables live bind updates (see BindEvent). Empty Addr disables them.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store serves lookups from an immutable snapshot that is swapped atomically on each full reload. Bind indexes are additionally patched in place by live updates (see ApplyBindEvent).
func (*Store) ApplyBindEvent ¶
ApplyBindEvent patches a single bind. During a reload the event is queued and applied once the new snapshot is published.