mirror of
https://github.com/qdm12/ddns-updater.git
synced 2026-08-02 02:28:40 -04:00
- Small UI adjustments - Only show last 2 previous IP addresses in notifications and UI - Database uses interfaces to be modular/pluggable in order to move away from sqlite - Less dependencies, it even uses a switch statement instead of httprouter - Updated golibs - Changed default logging format to `console` (zap) - Better code overall, modular updater and trigger system - Refactored readme - CI script improved
33 lines
654 B
Go
33 lines
654 B
Go
package data
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/qdm12/ddns-updater/internal/models"
|
|
)
|
|
|
|
func (db *database) Insert(record models.Record) (id int) {
|
|
db.Lock()
|
|
defer db.Unlock()
|
|
db.data = append(db.data, record)
|
|
return len(db.data) - 1
|
|
}
|
|
|
|
func (db *database) Select(id int) (record models.Record, err error) {
|
|
db.RLock()
|
|
defer db.RUnlock()
|
|
if id < 0 {
|
|
return record, fmt.Errorf("id %d cannot be lower than 0", id)
|
|
}
|
|
if id > len(db.data)-1 {
|
|
return record, fmt.Errorf("no record config found for id %d", id)
|
|
}
|
|
return db.data[id], nil
|
|
}
|
|
|
|
func (db *database) SelectAll() (records []models.Record) {
|
|
db.RLock()
|
|
defer db.RUnlock()
|
|
return db.data
|
|
}
|