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
39 lines
907 B
Go
39 lines
907 B
Go
package data
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/qdm12/ddns-updater/internal/models"
|
|
"github.com/qdm12/ddns-updater/internal/records"
|
|
)
|
|
|
|
func (db *database) GetEvents(domain, host string) (events []models.HistoryEvent, err error) {
|
|
return db.persistentDB.GetEvents(domain, host)
|
|
}
|
|
|
|
func (db *database) Update(id int, record records.Record) error {
|
|
db.Lock()
|
|
defer db.Unlock()
|
|
if id < 0 {
|
|
return fmt.Errorf("id %d cannot be lower than 0", id)
|
|
}
|
|
if id > len(db.data)-1 {
|
|
return fmt.Errorf("no record config found for id %d", id)
|
|
}
|
|
currentCount := len(db.data[id].History)
|
|
newCount := len(record.History)
|
|
db.data[id] = record
|
|
// new IP address added
|
|
if newCount > currentCount {
|
|
if err := db.persistentDB.StoreNewIP(
|
|
record.Settings.Domain(),
|
|
record.Settings.Host(),
|
|
record.History.GetCurrentIP(),
|
|
record.History.GetSuccessTime(),
|
|
); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
return nil
|
|
}
|