我正在尝试为服务发现实施领事,而在两件事上遇到了麻烦:连接到自定义DNS服务器,以及格式化我的net.LookupSRV()请求。
net.LookupSRV()
这是我要在go应用程序中查找的内容:
$ dig @127.0.0.1 -p 8600 serviceb.service.consul SRV ; <<>> DiG 9.8.4-rpz2+rl005.12-P1 <<>> @127.0.0.1 -p 8600 serviceb.service.consul SRV ; (1 server found) ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 4511 ;; flags: qr aa rd; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 2 ;; WARNING: recursion requested but not available ;; QUESTION SECTION: ;serviceb.service.consul. IN SRV ;; ANSWER SECTION: serviceb.service.consul. 0 IN SRV 1 1 80 az1-serviceb1.node.dc1.consul. serviceb.service.consul. 0 IN SRV 1 1 80 az2-serviceb2.node.dc1.consul. ;; ADDITIONAL SECTION: az1-serviceb1.node.dc1.consul. 0 IN A 10.6.41.22 az2-serviceb2.node.dc1.consul. 0 IN A 10.6.41.20 ;; Query time: 6 msec ;; SERVER: 127.0.0.1#8600(127.0.0.1) ;; WHEN: Fri May 16 15:09:28 2014 ;; MSG SIZE rcvd: 275
这是相关的代码。(我知道这是错误的,但是这样您就可以看到我正在尝试做的事情)
cname, addrs, err := net.LookupSRV("serviceb", "service", "consul") log.Printf("%+v %+v %+v", cname, addrs, err)
和输出:
2014/05/16 15:24:31 [] lookup _serviceb._service.consul: no such host
任何帮助,将不胜感激!谢谢
尝试使用更锋利的工具,例如github.com/miekg/dns包裹。上次查看它时,它几乎可以控制客户端设置的每一位来进行DNS解析。
github.com/miekg/dns