package database import ( "time" log "github.com/sirupsen/logrus" "dev.sum7.eu/genofire/golang-lib/file" "dev.sum7.eu/genofire/golang-lib/worker" ) type DB struct { Clients map[string]*Client `json:"client"` APs map[string]*AP `json:"ap"` worker *worker.Worker } func NewDB(path string) *DB { db := &DB{ Clients: make(map[string]*Client), APs: make(map[string]*AP), } file.ReadJSON(path, db) db.worker = worker.NewWorker(time.Minute, func() { file.SaveJSON(path, db) log.Debug("save db state") }) db.worker.Start() return db } func (db *DB) Close() { if db.worker != nil { db.worker.Close() } }