func (db *DB) RenewLease(mac net.HardwareAddr, end, graceEnd time.Time) (*Lease, error) {
	l := &Lease{}
	return l, db.db.Transaction(func(tx *gorm.DB) error {
		if err := tx.First(l, "mac_address = ?", mac.String()).Error; err != nil {
			return err
		}
		l.LeaseEnd = end
		l.LeaseGraceEnd = graceEnd
		return tx.Save(l).Error
	})
}
RenewLease renews a lease up to the given time.
package db
import (
	"net"
	"time"
	"github.com/jinzhu/gorm"
)
type Lease struct {
	MACAddress    string `gorm:"primary_key"`
	IPAddress     string `gorm:"unique"`
	Dynamic       bool
	LeaseEnd      time.Time
	LeaseGraceEnd time.Time
	Persistent    bool
}
func (l *Lease) IP() net.IP {
	return net.ParseIP(l.IPAddress).To4()
}
func (l *Lease) HardwareAddr() (net.HardwareAddr, error) {
	return net.ParseMAC(l.MACAddress)
}
func (db *DB) GetLease(mac net.HardwareAddr) (*Lease, error) {
	l := &Lease{}
	return l, db.db.Transaction(func(tx *gorm.DB) error {
		return tx.First(l, "mac_address = ?", mac.String()).Error
	})
}
func (db *DB) SetLease(mac net.HardwareAddr, ip net.IP, dynamic, persistent bool, end, graceEnd time.Time) error {
	return db.db.Transaction(func(tx *gorm.DB) error {
		return tx.Create(&Lease{
			MACAddress:    mac.String(),
			IPAddress:     ip.String(),
			Dynamic:       dynamic,
			LeaseEnd:      end,
			LeaseGraceEnd: graceEnd,
			Persistent:    persistent,
		}).Error
	})
}