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
+9.4k Golang : Launch Mac OS X Preview (or other OS) application from your program example
+5.8k Linux : Disable and enable IPv4 forwarding
+10.6k Golang : Bubble sort example
+21.1k Golang : For loop continue,break and range
+8.2k Prevent Write failed: Broken pipe problem during ssh session with screen command
+14.6k Golang : Execute function at intervals or after some delay
+5k Golang : Calculate a pip value and distance to target profit example
+8.2k Golang : Emulate NumPy way of creating matrix example
+26.1k Mac/Linux and Golang : Fix bind: address already in use error
+27.7k PHP : Count number of JSON items/objects
+11.6k Golang : Concurrency and goroutine example
+26.8k Golang : Find files by extension