Help us shape the future of Go! Take the 2026 Go Developer Survey

clientdb

package
v0.3.15 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 13, 2026 License: MIT Imports: 18 Imported by: 0

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 BindEventObject struct {
	ID        json.Number `json:"id"`
	IP        json.Number `json:"ip"`
	Mac       string      `json:"mac"`
	DeviceMac string      `json:"device_mac"`
	Port      json.Number `json:"port"`
}

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 New

func New(conf Config, lg *logger.Logger) (*Store, error)

New loads the database synchronously, so a broken source fails startup.

func (*Store) ApplyBindEvent

func (s *Store) ApplyBindEvent(ev BindEvent) error

ApplyBindEvent patches a single bind. During a reload the event is queued and applied once the new snapshot is published.

func (*Store) Close

func (s *Store) Close()

func (*Store) FindBinds added in v0.3.13

func (s *Store) FindBinds(dbName, mac, deviceMac, port string) []Bind

FindBinds returns all binds of source dbName matching the client mac, optionally narrowed by deviceMac and port. With an empty mac, deviceMac and port select every bind on that device port (ports given to a shared pool).

func (*Store) GetBindByID

func (s *Store) GetBindByID(dbName, id string) (Bind, bool)

func (*Store) GetDeviceByMac

func (s *Store) GetDeviceByMac(mac string) (Device, bool)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL