Remove utils package as it's only used in the dns package
This commit is contained in:
parent
e151e3dbfd
commit
4e16bab92e
24
dns/dns.go
24
dns/dns.go
@ -2,8 +2,8 @@ package dns
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"git.xbudex.com/buddy/update-dns/utils"
|
|
||||||
"github.com/dnsimple/dnsimple-go/dnsimple"
|
"github.com/dnsimple/dnsimple-go/dnsimple"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
@ -33,7 +33,7 @@ func (d *Client) GetRecords(host, kind string) ([]Record, error) {
|
|||||||
return nil, errors.Wrap(err, "unable to get account id")
|
return nil, errors.Wrap(err, "unable to get account id")
|
||||||
}
|
}
|
||||||
|
|
||||||
subdomain, domain, err := utils.SplitHost(host)
|
subdomain, domain, err := splitHost(host)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "unable to parse host")
|
return nil, errors.Wrap(err, "unable to parse host")
|
||||||
}
|
}
|
||||||
@ -59,7 +59,7 @@ func (d *Client) CreateRecord(host string, record Record) error {
|
|||||||
return errors.Wrap(err, "unable to get account id")
|
return errors.Wrap(err, "unable to get account id")
|
||||||
}
|
}
|
||||||
|
|
||||||
subdomain, domain, err := utils.SplitHost(host)
|
subdomain, domain, err := splitHost(host)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "unable to parse host")
|
return errors.Wrap(err, "unable to parse host")
|
||||||
}
|
}
|
||||||
@ -113,3 +113,21 @@ func (d *Client) getAccountID() (string, error) {
|
|||||||
d.accountID = strconv.Itoa(whoamiResponse.Data.Account.ID)
|
d.accountID = strconv.Itoa(whoamiResponse.Data.Account.ID)
|
||||||
return d.accountID, nil
|
return d.accountID, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// splitHost returns hostname into domain and subdomain strings.
|
||||||
|
// For example:
|
||||||
|
// "some.subdomain.example.com" → ("some.subdomain", "example.com", nil)
|
||||||
|
// "example.com" → ("", "example.com", nil)
|
||||||
|
func splitHost(host string) (subdomain string, domain string, err error) {
|
||||||
|
subdomains := strings.Split(host, ".")
|
||||||
|
|
||||||
|
if len(subdomains) >= 3 {
|
||||||
|
domain = strings.Join(subdomains[len(subdomains)-2:], ".")
|
||||||
|
subdomain = strings.Join(subdomains[:len(subdomains)-2], ".")
|
||||||
|
} else if len(subdomains) == 2 {
|
||||||
|
domain = strings.Join(subdomains, ".")
|
||||||
|
} else {
|
||||||
|
err = errors.New("invalid domain")
|
||||||
|
}
|
||||||
|
return subdomain, domain, err
|
||||||
|
}
|
||||||
|
|||||||
@ -1,25 +0,0 @@
|
|||||||
package utils
|
|
||||||
|
|
||||||
import (
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
|
||||||
)
|
|
||||||
|
|
||||||
// SplitHost returns hostname into domain and subdomain strings.
|
|
||||||
// For example:
|
|
||||||
// "some.subdomain.example.com" → ("some.subdomain", "example.com", nil)
|
|
||||||
// "example.com" → ("", "example.com", nil)
|
|
||||||
func SplitHost(host string) (subdomain string, domain string, err error) {
|
|
||||||
subdomains := strings.Split(host, ".")
|
|
||||||
|
|
||||||
if len(subdomains) >= 3 {
|
|
||||||
domain = strings.Join(subdomains[len(subdomains)-2:], ".")
|
|
||||||
subdomain = strings.Join(subdomains[:len(subdomains)-2], ".")
|
|
||||||
} else if len(subdomains) == 2 {
|
|
||||||
domain = strings.Join(subdomains, ".")
|
|
||||||
} else {
|
|
||||||
err = errors.New("invalid domain")
|
|
||||||
}
|
|
||||||
return subdomain, domain, err
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue
Block a user