func QuerySrvTargetHost()

in internal/loader/configuration_client_manager.go [243:285]


func QuerySrvTargetHost(ctx context.Context, host string) ([]string, error) {
	results := make([]string, 0)

	_, originRecords, err := net.DefaultResolver.LookupSRV(ctx, Origin, TCP, host)
	if err != nil {
		// If the host does not have SRV records => no replicas
		if dnsErr, ok := err.(*net.DNSError); ok && dnsErr.IsNotFound {
			return results, nil
		} else {
			return results, err
		}
	}

	if len(originRecords) == 0 {
		return results, nil
	}

	originHost := strings.TrimSuffix(originRecords[0].Target, ".")
	results = append(results, originHost)
	index := 0
	for {
		currentAlt := Alt + strconv.Itoa(index)
		_, altRecords, err := net.DefaultResolver.LookupSRV(ctx, currentAlt, TCP, originHost)
		if err != nil {
			// If the host does not have SRV records => no more replicas
			if dnsErr, ok := err.(*net.DNSError); ok && dnsErr.IsNotFound {
				break
			} else {
				return results, err
			}
		}

		for _, record := range altRecords {
			altHost := strings.TrimSuffix(record.Target, ".")
			if altHost != "" {
				results = append(results, altHost)
			}
		}
		index = index + 1
	}

	return results, nil
}