Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change format result data to slice #5

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

sitnikovv
Copy link

The format of the returned data has been changed from a map to a slice, since in a slice the data is already arranged in the required order.
Made as v3 since there is no backward compatibility.
The OrderSRV function was made public in order to make it possible in user functions to optionally sort data already received through net.LookupSRV and there was no need to go through this procedure again (DNS queries can be very long).
For example:

func ServiceDiscovery(service, proto, host string, sortWithWeight bool) ([]string, error) {
	_, addrs, err := net.LookupSRV(service, proto, host)
	if err != nil {
		return nil, err
	}
	if sortWithWeight {
		_, addrs = OrderSRV(addrs)
	}

	result := make([]string, len(addrs))
	for i, srv := range addrs {
		result[i] = strings.TrimRight(srv.Target, ".") + ":" + strconv.Itoa(int(srv.Port))
	}

	return result, nil
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant