示例#1
0
文件: service.go 项目: ozym/zone
// Dynamically remove a full set of RR records stored in DNS
func (s *Service) RemoveName(zone string, rr []dns.RR) error {
	m := new(dns.Msg)

	m.SetUpdate(zone)
	m.SetTsig(dns.Fqdn(s.Key), dns.HmacMD5, 300, time.Now().Unix())
	m.RemoveName(rr)

	h, err := s.ServerPort()
	if err != nil {
		return err
	}

	c := new(dns.Client)
	c.TsigSecret = map[string]string{dns.Fqdn(s.Key): s.Secret}

	r, _, err := c.Exchange(m, h)
	if err != nil {
		return err
	}

	if r.Rcode != dns.RcodeSuccess {
		return errors.New(fmt.Sprintf("invalid exchange answer"))
	}

	return nil
}