mirror of
https://github.com/AuxXxilium/docker-ddns-server.git
synced 2024-11-23 23:00:59 +07:00
34 lines
932 B
Go
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
|
|
}
|