Go program to find SRV service record of a domain
The LookupSRV function tries to resolve an SRV query of the given service, protocol, and domain name. The second parameter is "tcp" or "udp". The returned records are sorted by priority and randomized by weight within a priority.
Example
package main
import (
"fmt"
"net"
)
func main() {
cname, srvs, err := net.LookupSRV("xmpp-server", "tcp", "golang.org")
if err != nil {
panic(err)
}
fmt.Printf("\ncname: %s \n\n", cname)
for _, srv := range srvs {
fmt.Printf("%v:%v:%d:%d\n", srv.Target, srv.Port, srv.Priority, srv.Weight)
}
}
The output below demonstrates the CNAME return, followed by the SRV record target, port, priority, and weight separated by a colon.
cname: _xmpp-server._tcp.golang.org.
Most Helpful This Week
Golang program to generate number of slices permutations of number entered by user
Program to print full pyramid using star
How append a slice to an existing slice in Golang?
Example: ReadAll, ReadDir, and ReadFile from IO Package
Naming Conventions for Golang Functions
Web Application to generate QR code in Golang