package dns import ( "grow.rievo.dev/discordBots/cmd/domaincheckbot/repository" "net" "sort" ) func CheckDomain(domain string) repository.Domain { nameservers, err := net.LookupNS(domain) if len(nameservers) > 0 && err == nil { return repository.Domain{ Name: domain, NS: nsToArray(nameservers), } } return repository.Domain{ Name: domain, NS: []string{}, } } func nsToArray(nameservers []*net.NS) []string { var nsArray []string for _, nameserver := range nameservers { nsArray = append(nsArray, nameserver.Host) } sort.SliceStable(nsArray, func(i, j int) bool { return nsArray[i] < nsArray[j] }) return nsArray }