From 8ae1f7edcf1b154c11c104ec98e8b3c44ac64477 Mon Sep 17 00:00:00 2001 From: Ben Date: Wed, 28 Jul 2021 23:16:13 +0200 Subject: [PATCH 1/2] fix model validation and preloading --- .travis.yml | 6 +++--- dyndns/handler/cname.go | 2 +- dyndns/handler/host.go | 1 - dyndns/model/host.go | 2 +- 4 files changed, 5 insertions(+), 6 deletions(-) diff --git a/.travis.yml b/.travis.yml index bb60f0d..c78bcf9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,3 @@ -dist: bionic - language: go env: GO111MODULE=on @@ -11,8 +9,10 @@ go: git: depth: 1 -script: +before_script: - cd dyndns + +script: - go test -v ./... - go build ./... diff --git a/dyndns/handler/cname.go b/dyndns/handler/cname.go index 10038f2..eb88217 100644 --- a/dyndns/handler/cname.go +++ b/dyndns/handler/cname.go @@ -97,7 +97,7 @@ func (h *Handler) DeleteCName(c echo.Context) (err error) { } cname := &model.CName{} - if err = h.DB.First(cname, id).Error; err != nil { + if err = h.DB.Preload("Target").First(cname, id).Error; err != nil { return c.JSON(http.StatusBadRequest, &Error{err.Error()}) } diff --git a/dyndns/handler/host.go b/dyndns/handler/host.go index ce66716..979ee3c 100644 --- a/dyndns/handler/host.go +++ b/dyndns/handler/host.go @@ -292,7 +292,6 @@ func (h *Handler) UpdateIP(c echo.Context) (err error) { } func (h *Handler) checkUniqueHostname(hostname, domain string) error { - fmt.Println(hostname, domain) hosts := new([]model.Host) if err := h.DB.Where(&model.Host{Hostname: hostname, Domain: domain}).Find(hosts).Error; err != nil { return err diff --git a/dyndns/model/host.go b/dyndns/model/host.go index af3e084..25df51a 100644 --- a/dyndns/model/host.go +++ b/dyndns/model/host.go @@ -10,7 +10,7 @@ import ( 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"` + Domain string `gorm:"unique_index:idx_host_domain;not null" form:"domain" 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"` From eb947bda401e55790747fc58210d4c5eef10b0ac Mon Sep 17 00:00:00 2001 From: Ben Date: Wed, 28 Jul 2021 23:21:34 +0200 Subject: [PATCH 2/2] build on older go versions for travis compatibility --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index c78bcf9..fa177a8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,8 +3,8 @@ language: go env: GO111MODULE=on go: - - 1.15.x - - 1.16.x + - 1.13.x + - 1.14.x git: depth: 1