From 19f03904544edbe22e836e4127f545bfa880923f Mon Sep 17 00:00:00 2001 From: Pierre-Olivier Mercier Date: Sun, 14 Jun 2020 23:25:02 +0200 Subject: [PATCH] Remove the subdomain when removing the last service of a subdomain --- model/zone.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/model/zone.go b/model/zone.go index 09959e4..604c232 100644 --- a/model/zone.go +++ b/model/zone.go @@ -82,7 +82,11 @@ func (z *Zone) EraseService(subdomain string, origin string, id []byte, s *Servi if subdomain == "" && svc.Type == "svcs.Origin" { return errors.New("You cannot delete this service. It is mandatory.") } - z.Services[subdomain] = append(z.Services[subdomain][:k], z.Services[subdomain][k+1:]...) + if len(z.Services[subdomain]) <= 1 { + delete(z.Services, subdomain) + } else { + z.Services[subdomain] = append(z.Services[subdomain][:k], z.Services[subdomain][k+1:]...) + } } else { s.Comment = s.GenComment(origin) s.NbResources = s.GetNbResources()