40 lines
863 B
Go
40 lines
863 B
Go
package updateip
|
|
|
|
import "strings"
|
|
|
|
// Canonicalize a DNS record.
|
|
func Canonicalize(domainName, recordName string) string {
|
|
if recordName == "@" {
|
|
return ToFqdn(domainName)
|
|
} else if strings.HasSuffix(recordName, ".@") {
|
|
return ToFqdn(strings.TrimSuffix(recordName, "@") + domainName)
|
|
}
|
|
return ToFqdn(recordName)
|
|
}
|
|
|
|
// IsFqdn checks if the label is a full-qualified name.
|
|
func IsFqdn(name string) bool {
|
|
return strings.HasSuffix(name, ".")
|
|
}
|
|
|
|
// ToFqdn converts the name into a fqdn appending a trailing dot.
|
|
func ToFqdn(name string) string {
|
|
if name == "@" {
|
|
return name
|
|
}
|
|
n := len(name)
|
|
if n == 0 || name[n-1] == '.' {
|
|
return name
|
|
}
|
|
return name + "."
|
|
}
|
|
|
|
// UnFqdn converts the fqdn into a name removing the trailing dot.
|
|
func UnFqdn(name string) string {
|
|
n := len(name)
|
|
if n != 0 && name[n-1] == '.' {
|
|
return name[:n-1]
|
|
}
|
|
return name
|
|
}
|