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
Program in Go language to Find Largest Element of an Array
GO Hello World program
How to Iterate Over a Slice in Golang?
Golang program for implementation of Shell Sort
Golang write CSV records
Creating Instances of Struct Types
Golang program for implementation of ZigZag Matrix
How do you handle HTTP server health checks in Go?
Program in Go language to print Pascal's Triangle
Golang program for implementation of Pancake Sort