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
GO language program with example of Array Reverse Sort Functions for integer and strings
Example of Interface with Type Embedding and Method Overriding in GO language
Golang program for implementation of Longest Common Sub-sequence
Print inverted full pyramid using star
Program in Go language to Find Largest Element of an Array
Creating Instances of Struct Types