From db39682318225a250c11e58335742db94d88a10e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=96=9F=E9=85=8C=20=E9=B5=AC=E5=85=84?= Date: Mon, 14 Mar 2022 07:23:54 +0900 Subject: [PATCH] wrong way to trimsuffix not trimright --- freedns/freedns.go | 4 ++-- main.go | 5 ++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/freedns/freedns.go b/freedns/freedns.go index 9f91f00..f536bda 100755 --- a/freedns/freedns.go +++ b/freedns/freedns.go @@ -35,7 +35,7 @@ const URI_DELETE_RECORD = "https://freedns.afraid.org/subdomain/delete2.php?data // const URI_LOGIN string = "http://127.0.0.1:1234/" func GetDomainFromZone(Zone string) string { - _segs := strings.Split(strings.TrimRight(Zone, "."), ".") + _segs := strings.Split(strings.TrimSuffix(Zone, "."), ".") _segs = _segs[len(_segs)-2:] return strings.Join(_segs, ".") } @@ -299,7 +299,7 @@ loop: if CurrRecordType == RecordType && CurrRecordAddr == Subdomain { if _Addr == Address { return CurrRecordId, nil - } else if strings.HasSuffix(_Addr, "...") && strings.HasPrefix(Address, strings.TrimRight(_Addr, "...")) { + } else if strings.HasSuffix(_Addr, "...") && strings.HasPrefix(Address, strings.TrimSuffix(_Addr, "...")) { DeepSearchCandidates = append(DeepSearchCandidates, CurrRecordId) } } diff --git a/main.go b/main.go index 183a0c5..d40a833 100644 --- a/main.go +++ b/main.go @@ -116,10 +116,9 @@ func (c *customDNSProviderSolver) Present(ch *v1alpha1.ChallengeRequest) error { return err } - _zone := strings.TrimRight(ch.ResolvedFQDN, "."+ch.ResolvedZone) + _zone := strings.TrimSuffix(ch.ResolvedFQDN, "."+ch.ResolvedZone) _key := "\"" + ch.Key + "\"" - fmt.Println("ADD - "+_zone, _key) err = dnsObj.AddRecord("TXT", _zone, _key, false, "") if err != nil { return err @@ -138,7 +137,7 @@ func (c *customDNSProviderSolver) Present(ch *v1alpha1.ChallengeRequest) error { func (c *customDNSProviderSolver) CleanUp(ch *v1alpha1.ChallengeRequest) error { _key := "\"" + ch.Key + "\"" - _id, err := c.freedns.FindRecord(strings.TrimRight(ch.ResolvedZone, "."), "TXT", _key) + _id, err := c.freedns.FindRecord(strings.TrimSuffix(ch.ResolvedZone, "."), "TXT", _key) if _id != "" { err = c.freedns.DeleteRecord(_id)