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


Golang Msg.SetNotify方法代碼示例

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


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

示例1: notify

// notify sends notifies to the configured remote servers. It will try up to three times
// before giving up on a specific remote. We will sequentially loop through "to"
// until they all have replied (or have 3 failed attempts).
func notify(zone string, to []string) error {
	m := new(dns.Msg)
	m.SetNotify(zone)
	c := new(dns.Client)

	for _, t := range to {
		if t == "*" {
			continue
		}
		if err := notifyAddr(c, m, t); err != nil {
			log.Printf("[ERROR] " + err.Error())
		} else {
			log.Printf("[INFO] Sent notify for zone %s to %s", zone, t)
		}
	}
	return nil
}
開發者ID:yuewko,項目名稱:coredns,代碼行數:20,代碼來源:notify.go

示例2: sendNotify

func sendNotify(servers []string, domain string) []NotifyResponse {

	if !strings.HasSuffix(domain, ".") {
		domain = domain + "."
	}

	if len(servers) == 0 {
		fmt.Println("No servers")
		resp := NotifyResponse{Result: "No servers", Error: true}
		fmt.Println("No servers")
		return []NotifyResponse{resp}
	}

	c := new(dns.Client)

	c.ReadTimeout = time.Duration(*timeout) * time.Millisecond

	m := new(dns.Msg)
	m.SetNotify(domain)

	wg := new(sync.WaitGroup)

	responseChannel := make(chan NotifyResponse, len(servers))

	for _, server := range servers {

		go func(server string) {

			result := NotifyResponse{Server: server}

			wg.Add(1)

			defer func() {
				wg.Done()
				if result.Error || !*quiet {
					fmt.Printf("%s: %s\n", result.Server, result.Result)
				}
				responseChannel <- result
			}()

			target, err := fixupHost(server)
			if err != nil {
				result.Result = fmt.Sprintf("%s: %s", server, err)
				fmt.Println(result.Result)
				result.Error = true
				return
			}

			result.Server = target

			if *verbose {
				fmt.Println("Sending notify to", target)
			}

			resp, rtt, err := c.Exchange(m, target)

			if err != nil {
				result.Error = true
				result.Result = err.Error()
				return
			}

			ok := "ok"
			if !resp.Authoritative {
				ok = fmt.Sprintf("not ok (%s)", dns.RcodeToString[resp.Rcode])
			}

			result.Result = fmt.Sprintf("%s: %s (%s)",
				target, ok, rtt.String())

			responseChannel <- result
		}(server)

	}

	responses := make([]NotifyResponse, len(servers))

	for i := 0; i < len(servers); i++ {
		responses[i] = <-responseChannel
	}

	wg.Wait()

	return responses

}
開發者ID:postfix,項目名稱:dns-notify,代碼行數:86,代碼來源:dns-notify.go


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