mirror of
https://github.com/qdm12/ddns-updater.git
synced 2026-08-02 10:38:41 -04:00
- Only calls DNS API(s) once the public IP address changes - Only one ip method per ip version (ipv4, ipv6, ipv4/v6) - Gets the ip address once every period for all records - More object oriented coding instead of functional - Support to update ipv4 and ipv6 records separately, for supported DNS providers
33 lines
658 B
Go
33 lines
658 B
Go
package data
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/qdm12/ddns-updater/internal/records"
|
|
)
|
|
|
|
func (db *database) Insert(record records.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 records.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 []records.Record) {
|
|
db.RLock()
|
|
defer db.RUnlock()
|
|
return db.data
|
|
}
|