當前位置: 首頁>>代碼示例>>Golang>>正文


Golang SRV.Target方法代碼示例

本文整理匯總了Golang中github.com/miekg/dns.SRV.Target方法的典型用法代碼示例。如果您正苦於以下問題:Golang SRV.Target方法的具體用法?Golang SRV.Target怎麽用?Golang SRV.Target使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/miekg/dns.SRV的用法示例。


在下文中一共展示了SRV.Target方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: answerSRV

func answerSRV(q *dns.Question, v *DNSValue) dns.RR {
	answer := new(dns.SRV)
	answer.Header().Name = q.Name
	answer.Header().Rrtype = dns.TypeSRV
	answer.Header().Class = dns.ClassINET
	answer.Priority = 50 // default if not defined
	priority, err := strconv.Atoi(v.Attr["priority"])
	if err == nil {
		answer.Priority = uint16(priority)
	}
	answer.Weight = 50 // default if not defined
	weight, err := strconv.Atoi(v.Attr["weight"])
	if err == nil {
		answer.Weight = uint16(weight)
	}
	answer.Port = 0 // default if not defined
	port, err := strconv.Atoi(v.Attr["port"])
	if err == nil {
		answer.Port = uint16(port)
	}
	if target, ok := v.Attr["target"]; ok {
		answer.Target = strings.TrimSuffix(target, ".") + "."
	} else if v.Value != "" { // allows for simplified setting
		targetParts := strings.Split(v.Value, ":")
		answer.Target = strings.TrimSuffix(targetParts[0], ".") + "."
		if len(targetParts) > 1 {
			port, err := strconv.Atoi(targetParts[1])
			if err == nil {
				answer.Port = uint16(port)
			}
		}
	}
	return answer
}
開發者ID:guilhem,項目名稱:netcore,代碼行數:34,代碼來源:dns.go

示例2: handleSRVQuery

func (r *resolver) handleSRVQuery(svc string, query *dns.Msg) (*dns.Msg, error) {

	srv, ip := r.backend.ResolveService(svc)

	if len(srv) == 0 {
		return nil, nil
	}
	if len(srv) != len(ip) {
		return nil, fmt.Errorf("invalid reply for SRV query %s", svc)
	}

	resp := createRespMsg(query)

	for i, r := range srv {
		rr := new(dns.SRV)
		rr.Hdr = dns.RR_Header{Name: svc, Rrtype: dns.TypePTR, Class: dns.ClassINET, Ttl: respTTL}
		rr.Port = r.Port
		rr.Target = r.Target
		resp.Answer = append(resp.Answer, rr)

		rr1 := new(dns.A)
		rr1.Hdr = dns.RR_Header{Name: r.Target, Rrtype: dns.TypeA, Class: dns.ClassINET, Ttl: respTTL}
		rr1.A = ip[i]
		resp.Extra = append(resp.Extra, rr1)
	}
	return resp, nil

}
開發者ID:jwhonce,項目名稱:docker,代碼行數:28,代碼來源:resolver.go

示例3: Test_convertAnswersToSRV_convertsAnswers

func (s *DNSXmppSuite) Test_convertAnswersToSRV_convertsAnswers(c *C) {
	cn := new(dns.CNAME)
	srv := new(dns.SRV)
	srv.Target = "foo2.com"

	in := make([]dns.RR, 2)
	in[0] = cn
	in[1] = srv
	res := convertAnswersToSRV(in)

	c.Assert(res, HasLen, 1)
	c.Assert(res[0].Target, Equals, "foo2.com")
}
開發者ID:0x27,項目名稱:coyim,代碼行數:13,代碼來源:dns_test.go

示例4: Test_convertAnswerToSRV_returnsAValidNetSRV

func (s *DNSXmppSuite) Test_convertAnswerToSRV_returnsAValidNetSRV(c *C) {
	srv := new(dns.SRV)
	srv.Target = "foo.com"
	srv.Port = 123
	srv.Priority = 5
	srv.Weight = 42
	res := convertAnswerToSRV(srv)
	c.Assert(res, Not(IsNil))
	c.Assert(res.Target, Equals, "foo.com")
	c.Assert(res.Port, Equals, uint16(123))
	c.Assert(res.Priority, Equals, uint16(5))
	c.Assert(res.Weight, Equals, uint16(42))
}
開發者ID:0x27,項目名稱:coyim,代碼行數:13,代碼來源:dns_test.go


注:本文中的github.com/miekg/dns.SRV.Target方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。