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


Golang dns.NewRR函數代碼示例

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


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

示例1: TestMXHandle

func TestMXHandle(t *testing.T) {
	msg := &mdns.Msg{}

	zone := &config.Zone{
		MX: `1 test1.mail.server
10 test2.mail.server`,
	}

	question := mdns.Question{
		Name: "test.com",
	}

	mx := &mxHandler{}

	err := mx.Handle(msg, zone, question)
	assert.Nil(t, err)

	expectedMsg := &mdns.Msg{}
	rr, err := mdns.NewRR("test.com. 3600 IN MX 1 test1.mail.server")
	assert.Nil(t, err)
	expectedMsg.Answer = append(expectedMsg.Answer, rr)
	rr, err = mdns.NewRR("test.com. 3600 IN MX 10 test2.mail.server")
	assert.Nil(t, err)
	expectedMsg.Answer = append(expectedMsg.Answer, rr)

	assert.Exactly(t, msg.Answer, expectedMsg.Answer)
}
開發者ID:parkomat,項目名稱:parkomat,代碼行數:27,代碼來源:mx_test.go

示例2: TestTXTHandle

func TestTXTHandle(t *testing.T) {
	msg := &mdns.Msg{}

	zone := &config.Zone{
		TXT: `never gonna
		give you up
`,
	}

	question := mdns.Question{
		Name: "test.com",
	}

	txt := &txtHandler{}

	err := txt.Handle(msg, zone, question)
	assert.Nil(t, err)

	expectedMsg := &mdns.Msg{}
	rr, err := mdns.NewRR("test.com. 3600 IN TXT never gonna")
	assert.Nil(t, err)
	expectedMsg.Answer = append(expectedMsg.Answer, rr)
	rr, err = mdns.NewRR("test.com. 3600 IN TXT give you up")
	assert.Nil(t, err)
	expectedMsg.Answer = append(expectedMsg.Answer, rr)

	assert.Exactly(t, msg.Answer, expectedMsg.Answer)
}
開發者ID:parkomat,項目名稱:parkomat,代碼行數:28,代碼來源:txt_test.go

示例3: Handle

// Handle produces reply for NS question
func (n *nsHandler) Handle(msg *mdns.Msg, zone *config.Zone, question mdns.Question) (err error) {
	for _, server := range n.config.DNS.Servers {
		s := strings.Join([]string{
			question.Name,
			"3600",
			"IN",
			"NS",
			server.Name,
		}, " ")

		rr, err := mdns.NewRR(s)
		if err == nil {
			msg.Answer = append(msg.Answer, rr)
		}
	}

	for _, server := range n.config.DNS.Servers {
		s := strings.Join([]string{
			server.Name,
			"3600",
			"IN",
			"A",
			server.IP,
		}, " ")
		rr, err := mdns.NewRR(s)
		if err == nil {
			msg.Extra = append(msg.Extra, rr)
		}
	}
	return
}
開發者ID:parkomat,項目名稱:parkomat,代碼行數:32,代碼來源:ns.go

示例4: localRR

func localRR(hostname string, services map[string]int) (map[string][]dns.RR, error) {
	rrs := map[string][]dns.RR{}
	addrs, err := net.InterfaceAddrs()
	if err != nil {
		return nil, err
	}
	for _, addr := range addrs {
		var ip net.IP
		switch v := addr.(type) {
		case *net.IPNet:
			ip = v.IP
		case *net.IPAddr:
			ip = v.IP
		}
		if ip.IsLoopback() {
			continue
		}
		if ip = ip.To4(); ip != nil {
			for _, record := range []string{
				fmt.Sprintf("%s.local. 10 IN A %s", hostname, ip.String()),
				fmt.Sprintf("%d.%d.%d.%d.in-addr.arpa. 10 IN PTR %s.local.",
					ip[3], ip[2], ip[1], ip[0], hostname),
			} {
				if rr, err := dns.NewRR(record); err != nil {
					return nil, err
				} else {
					rrs[rr.Header().Name] = append(rrs[rr.Header().Name], rr)
				}
			}

			for s, port := range services {
				for _, record := range []string{
					fmt.Sprintf("%s.local. 60 IN PTR %s.%s.local.", s, hostname, s),
					fmt.Sprintf("%s.%s.local. 60 IN SRV 0 0 %d %s.local.",
						hostname, s, port, hostname),
					fmt.Sprintf("%s.%s.local. 60 IN TXT \"\"", hostname, s),
					fmt.Sprintf("_services._dns-sd._udp.local. 60 IN PTR %s.local.", s),
				} {
					if rr, err := dns.NewRR(record); err != nil {
						return nil, err
					} else {
						rrs[rr.Header().Name] = append(rrs[rr.Header().Name], rr)
					}
				}
			}
		}
	}
	return rrs, nil
}
開發者ID:zserge,項目名稱:mdns,代碼行數:49,代碼來源:mdns.go

示例5: getRecord

func getRecord(domain string, rtype uint16) (rr dns.RR, err error) {
	if *debug {
		Log.Printf("getRecord: domain: %s, resource type: %d\n", domain, rtype)
	}

	key, _ := getKey(domain, rtype)
	var v []byte

	err = bdb.View(func(tx *bolt.Tx) error {
		b := tx.Bucket([]byte(rrBucket))
		v = b.Get([]byte(key))

		if string(v) == "" {
			e := errors.New("Record not found, key: " + key)
			Log.Println(e.Error())

			return e
		}

		return nil
	})

	if err == nil {
		rr, err = dns.NewRR(string(v))
	}

	return rr, err
}
開發者ID:ae6rt,項目名稱:dyndns,代碼行數:28,代碼來源:main.go

示例6: mustNewRR

func mustNewRR(tb testing.TB, s string) dns.RR {
	rr, err := dns.NewRR(s)
	if err != nil {
		tb.Fatalf("invalid RR %q: %v", s, err)
	}
	return rr
}
開發者ID:albertito,項目名稱:dnss,代碼行數:7,代碼來源:caching_test.go

示例7: mustParseRR

func mustParseRR(s string) dns.RR {
	rr, err := dns.NewRR(s)
	if err != nil {
		panic(err)
	}
	return rr
}
開發者ID:TheBigBear,項目名稱:cli53,代碼行數:7,代碼來源:bind_test.go

示例8: TestSOAHandle

func TestSOAHandle(t *testing.T) {
	saved := now
	now = func() int64 {
		return 0
	}
	defer func() {
		now = saved
	}()

	msg := &mdns.Msg{}

	question := mdns.Question{
		Name: "test.com",
	}

	soa := NewSOAHandler("kitty")

	err := soa.Handle(msg, nil, question)
	assert.Nil(t, err)

	expectedMsg := &mdns.Msg{}
	rr, err := mdns.NewRR("test.com. 3600 IN SOA kitty admin.test.com 0 10000 2400 604800 3600")
	assert.Nil(t, err)
	expectedMsg.Answer = append(expectedMsg.Answer, rr)

	assert.Exactly(t, msg.Answer, expectedMsg.Answer)
}
開發者ID:parkomat,項目名稱:parkomat,代碼行數:27,代碼來源:soa_test.go

示例9: mustRR

func mustRR(s string) miekgdns.RR {
	r, err := miekgdns.NewRR(s)
	if err != nil {
		log.Fatal(err)
	}
	return r
}
開發者ID:cloudfoundry-incubator,項目名稱:consul-release,代碼行數:7,代碼來源:server.go

示例10: putincache

func putincache(results []*dns.Msg) {
	var newans []dns.RR
	var minttl uint32
	var question dns.Question
	for _, r := range results {
		if iscachable(r) {
			//fmt.Printf("%s\n", r.Answer)
			question = r.Question[0]
			for _, ans := range r.Answer {
				//fmt.Printf("%s\n", ans.Header().Ttl)
				if minttl == 0 || minttl > ans.Header().Ttl {
					minttl = ans.Header().Ttl
				}
				if ans.Header().Rrtype == dns.TypeA {
					line := fmt.Sprintf("%s %d IN A %s", r.Question[0].Name, minttl, ans.(*dns.A).A)
					rr, _ := dns.NewRR(line)
					//fmt.Println(rr)
					newans = append(newans, rr)
				}
			}
			//Cache forever for now.
			//cache[r.Question[0]] = cacheobj{ans: r.Answer, expire: time.Now()}
			//fmt.Printf("Cachable for %d\n", minttl)
		}
	}
	fmt.Printf("Putting %d\n", len(newans))
	if len(newans) > 0 {
		cacheput <- putrequest{question: question, ttl: minttl, result: newans}
	}
}
開發者ID:sajal,項目名稱:multiget,代碼行數:30,代碼來源:resolver.go

示例11: setupSOA

func setupSOA(Zone *Zone) {
	label := Zone.Labels[""]

	primaryNs := "ns"

	if record, ok := label.Records[dns.TypeNS]; ok {
		primaryNs = record[0].RR.(*dns.RR_NS).Ns
	}

	s := Zone.Origin + ". 3600 IN SOA " +
		primaryNs + " support.bitnames.com. " +
		strconv.Itoa(Zone.Options.Serial) +
		" 5400 5400 2419200 " +
		strconv.Itoa(Zone.Options.Ttl)

	log.Println("SOA: ", s)

	rr, err := dns.NewRR(s)

	if err != nil {
		log.Println("SOA Error", err)
		panic("Could not setup SOA")
	}

	record := Record{RR: rr}

	label.Records[dns.TypeSOA] = make([]Record, 1)
	label.Records[dns.TypeSOA][0] = record

}
開發者ID:uriel,項目名稱:geodns,代碼行數:30,代碼來源:config.go

示例12: answerQuestion

// answerQuestion returns resource record answers for the domain in question
func answerQuestion(name string, qtype uint16) []dns.RR {
	answers := make([]dns.RR, 0)

	// get the resource (check memory, cache, and (todo:) upstream)
	r, err := shaman.GetRecord(name)
	if err != nil {
		config.Log.Trace("Failed to get records for '%s' - %v", name, err)
	}

	// validate the records and append correct type to answers[]
	for _, record := range r.StringSlice() {
		entry, err := dns.NewRR(record)
		if err != nil {
			config.Log.Debug("Failed to create RR from record - %v", err)
			continue
		}
		entry.Header().Name = name
		if entry.Header().Rrtype == qtype || qtype == dns.TypeANY {
			answers = append(answers, entry)
		}
	}

	// todo: should `shaman.GetRecord` be wildcard aware (*.domain.com) or is this ok
	// recursively resolve if no records found
	if len(answers) == 0 {
		name = stripSubdomain(name)
		if len(name) > 0 {
			config.Log.Trace("Checking again with '%v'", name)
			return answerQuestion(name, qtype)
		}
	}

	return answers
}
開發者ID:nanopack,項目名稱:shaman,代碼行數:35,代碼來源:dns.go

示例13: TestPrivateByteSlice

func TestPrivateByteSlice(t *testing.T) {
	dns.PrivateHandle("ISBN", TypeISBN, NewISBN)
	defer dns.PrivateHandleRemove(TypeISBN)

	rr, err := dns.NewRR(testrecord)
	if err != nil {
		t.Fatal(err)
	}

	buf := make([]byte, 100)
	off, err := dns.PackRR(rr, buf, 0, nil, false)
	if err != nil {
		t.Errorf("got error packing ISBN: %v", err)
	}

	custrr := rr.(*dns.PrivateRR)
	if ln := custrr.Data.Len() + len(custrr.Header().Name) + 11; ln != off {
		t.Errorf("offset is not matching to length of Private RR: %d!=%d", off, ln)
	}

	rr1, off1, err := dns.UnpackRR(buf[:off], 0)
	if err != nil {
		t.Errorf("got error unpacking ISBN: %v", err)
	}

	if off1 != off {
		t.Errorf("Offset after unpacking differs: %d != %d", off1, off)
	}

	if rr1.String() != testrecord {
		t.Errorf("Record string representation did not match original %#v != %#v", rr1.String(), testrecord)
	} else {
		t.Log(rr1.String())
	}
}
開發者ID:GaizkaRubio,項目名稱:mesos-dns,代碼行數:35,代碼來源:privaterr_test.go

示例14: rootZone

func rootZone(w dns.ResponseWriter, req *dns.Msg) {
	m := new(dns.Msg)
	m.SetReply(req)
	rr, _ := dns.NewRR(". 0 IN SOA a.root-servers.net. nstld.verisign-grs.com. 2016110600 1800 900 604800 86400")
	m.Ns = []dns.RR{rr}
	w.WriteMsg(m)
}
開發者ID:zaccone,項目名稱:goSPF,代碼行數:7,代碼來源:parser_test.go

示例15: metazone

// Create DNS packet with the config in line with the meta zone
// paper from Vixie
func metazone(w dns.ResponseWriter, req *dns.Msg, c *Config) {
	logPrintf("metazone command")

	// Only called when the class is CHAOS
	// PTR zone.	-> get a list of zone names

	// Top level zone stuff -- list them
	if strings.ToUpper(req.Question[0].Name) == "ZONE." {
		m := new(dns.Msg)
		m.SetReply(req)
		for _, z := range c.Zones {
			ptr, _ := dns.NewRR("zone. 0 CH PTR " + z.Origin)
			m.Answer = append(m.Answer, ptr)
		}
		w.WriteMsg(m)
		return
	}

	// Top level user stuff -- list them
	if strings.ToUpper(req.Question[0].Name) == "USER." {

	}

	// <zone>.ZONE.

	formerr(w, req)
	return
}
開發者ID:valm0unt,項目名稱:fks,代碼行數:30,代碼來源:config.go


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