Golang net.LookupSRV() function example
package net
Golang net.LookupSRV() function usage example
package main
import (
"fmt"
"net"
)
func main() {
//-------------------------
service := "xmpp-server"
protocol := "tcp"
name := "google.com"
cname, addresses, err := net.LookupSRV(service, protocol, name)
if err != nil {
panic(err)
}
fmt.Printf("cname : %s \n", cname)
for i := 0; i < len(addresses); i++ {
fmt.Printf("addrs[%d].Target : %s \n", i, addresses[i].Target)
fmt.Printf("addrs[%d].Port : %d \n", i, addresses[i].Port)
fmt.Printf("addrs[%d].Priority : %d \n", i, addresses[i].Priority)
fmt.Printf("addrs[%d].Weight : %d \n", i, addresses[i].Weight)
}
}
Sample output :
cname : xmpp-server.tcp.google.com.
addrs[0].Target : xmpp-server.l.google.com.
addrs[0].Port : 5269
addrs[0].Priority : 5
addrs[0].Weight : 0
addrs1.Target : alt1.xmpp-server.l.google.com.
addrs1.Port : 5269
addrs1.Priority : 20
addrs1.Weight : 0
addrs2.Target : alt2.xmpp-server.l.google.com.
addrs2.Port : 5269
addrs2.Priority : 20
addrs2.Weight : 0
addrs[3].Target : alt3.xmpp-server.l.google.com.
addrs[3].Port : 5269
addrs[3].Priority : 20
addrs[3].Weight : 0
addrs[4].Target : alt4.xmpp-server.l.google.com.
addrs[4].Port : 5269
addrs[4].Priority : 20
addrs[4].Weight : 0
References :
Advertisement
Something interesting
Tutorials
+7.9k Setting $GOPATH environment variable for Unix/Linux and Windows
+14.2k Elastic Search : Mapping date format and sort by date
+5.6k Fix fatal error: evacuation not done in time problem
+19.9k Golang : How to get time from unix nano example
+10.1k Golang : How to get quoted string into another string?
+9.6k Golang : Quadratic example
+7.6k Android Studio : AlertDialog to get user attention example
+15.3k Golang : Get all local users and print out their home directory, description and group id
+19.3k Golang : Get RGBA values of each image pixel
+8.2k Golang : Metaprogramming example of wrapping a function
+13.6k Golang : Query string with space symbol %20 in between
+4.7k Unix/Linux : How to pipe/save output of a command to file?