mirror of
https://github.com/qdm12/ddns-updater.git
synced 2026-07-29 00:52:37 -04:00
- Change database id to be `uint` instead of `int` - Define and use sentinel errors - Return `string` instead of `error` when appropriate (linode)
26 lines
496 B
Go
26 lines
496 B
Go
package data
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
|
|
"github.com/qdm12/ddns-updater/internal/records"
|
|
)
|
|
|
|
var ErrRecordNotFound = errors.New("record not found")
|
|
|
|
func (db *Database) Select(id uint) (record records.Record, err error) {
|
|
db.RLock()
|
|
defer db.RUnlock()
|
|
if int(id) > len(db.data)-1 {
|
|
return record, fmt.Errorf("%w: for id %d", ErrRecordNotFound, id)
|
|
}
|
|
return db.data[id], nil
|
|
}
|
|
|
|
func (db *Database) SelectAll() (records []records.Record) {
|
|
db.RLock()
|
|
defer db.RUnlock()
|
|
return db.data
|
|
}
|