docker-ddns-server/dyndns/model/host.go
2020-04-27 20:37:22 +02:00

34 lines
932 B
Go

package model
import (
"time"
"github.com/jinzhu/gorm"
)
type Host struct {
gorm.Model
Hostname string `gorm:"unique_index:idx_host_domain;not null" form:"hostname" validate:"required,hostname"`
Domain string `gorm:"unique_index:idx_host_domain;not null" validate:"required,hostname"`
Ip string `form:"ip" validate:"omitempty,ipv4"`
Ttl int `form:"ttl" validate:"required,min=20,max=86400"`
LastUpdate time.Time `form:"lastupdate"`
UserName string `gorm:"unique" form:"username" validate:"min=8"`
Password string `form:"password" validate:"min=8"`
}
func (h *Host) UpdateHost(updateHost *Host) (updateRecord bool) {
updateRecord = false
if h.Ip != updateHost.Ip || h.Ttl != updateHost.Ttl {
updateRecord = true
h.LastUpdate = time.Now()
}
h.Ip = updateHost.Ip
h.Ttl = updateHost.Ttl
h.UserName = updateHost.UserName
h.Password = updateHost.Password
return
}