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
How to get first and last element of slice in Golang?
How to initialize a struct containing a slice of structs in Golang?
How do you create an HTTP server in Go?
Golang program for implementation of Linked List
GO Program to Calculate Sum of Natural Numbers Using for.....Loop
Print inverted full pyramid using star