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


Golang MX.Preference方法代碼示例

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


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

示例1: answerMX

func answerMX(q *dns.Question, v *DNSValue) dns.RR {
	answer := new(dns.MX)
	answer.Header().Name = q.Name
	answer.Header().Rrtype = dns.TypeMX
	answer.Header().Class = dns.ClassINET
	answer.Preference = 50 // default if not defined
	priority, err := strconv.Atoi(v.Attr["priority"])
	if err == nil {
		answer.Preference = uint16(priority)
	}
	if target, ok := v.Attr["target"]; ok {
		answer.Mx = strings.TrimSuffix(target, ".") + "."
	} else if v.Value != "" { // allows for simplified setting
		answer.Mx = strings.TrimSuffix(v.Value, ".") + "."
	}
	return answer
}
開發者ID:guilhem,項目名稱:netcore,代碼行數:17,代碼來源:dns.go

示例2: handleDnsMX

// handleDnsMX writes a MX record pointing to s.host into m for host name.
func (s *server) handleDnsMX(name host, m *dns.Msg) {
	r := new(dns.MX)
	r.Hdr = dns.RR_Header{
		Name:   name.dns(),
		Rrtype: dns.TypeMX,
		Class:  dns.ClassINET,
		Ttl:    3600,
	}
	r.Preference = 10
	r.Mx = s.self.dns()
	m.Answer = make([]dns.RR, 1)
	m.Answer[0] = r
}
開發者ID:dullgiulio,項目名稱:kuradns,代碼行數:14,代碼來源:dns.go

示例3: TestRRsToMapStrsWithOPTRecord

func TestRRsToMapStrsWithOPTRecord(t *testing.T) {
	o := new(mkdns.OPT)
	o.Hdr.Name = "." // MUST be the root zone, per definition.
	o.Hdr.Rrtype = mkdns.TypeOPT

	r := new(mkdns.MX)
	r.Hdr = mkdns.RR_Header{Name: "miek.nl.", Rrtype: mkdns.TypeMX,
		Class: mkdns.ClassINET, Ttl: 3600}
	r.Preference = 10
	r.Mx = "mx.miek.nl."

	// The OPT record is a psuedo-record so it doesn't become a real record
	// in our conversion, and there will be 1 entry instead of 2.
	mapStrs := rrsToMapStrs([]mkdns.RR{o, r})
	assert.Len(t, mapStrs, 1)

	mapStr := mapStrs[0]
	assert.Equal(t, "IN", mapStr["class"])
	assert.Equal(t, "MX", mapStr["type"])
	assert.Equal(t, "mx.miek.nl.", mapStr["data"])
	assert.Equal(t, "miek.nl.", mapStr["name"])
	assert.EqualValues(t, 10, mapStr["preference"])
}
開發者ID:ruflin,項目名稱:beats,代碼行數:23,代碼來源:dns_test.go


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