ResolveSRV resolves an SRV record using the default resolver
(ctx context.Context, service, proto, name string)
| 46 | |
| 47 | // ResolveSRV resolves an SRV record using the default resolver |
| 48 | func ResolveSRV(ctx context.Context, service, proto, name string) (string, uint16, error) { |
| 49 | _, addrs, err := net.DefaultResolver.LookupSRV(ctx, service, proto, name) |
| 50 | if err != nil { |
| 51 | return "", 0, err |
| 52 | } |
| 53 | if len(addrs) == 0 { |
| 54 | return "", 0, fmt.Errorf("no SRV records found") |
| 55 | } |
| 56 | // Return the first SRV target and port |
| 57 | return strings.TrimSuffix(addrs[0].Target, "."), addrs[0].Port, nil |
| 58 | } |