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


Golang dns.NewServeMux函數代碼示例

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


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

示例1: Run

func (s *Server) Run() {

	Handler := NewHandler()

	go Handler.PreparePool()

	fmt.Println(Handler.resolver.NameserversPool)

	tcpHandler := dns.NewServeMux()
	tcpHandler.HandleFunc(".", Handler.DoTCP)

	udpHandler := dns.NewServeMux()
	udpHandler.HandleFunc(".", Handler.DoUDP)

	tcpServer := &dns.Server{Addr: s.Addr(),
		Net:          "tcp",
		Handler:      tcpHandler,
		ReadTimeout:  s.rTimeout,
		WriteTimeout: s.wTimeout,
	}

	udpServer := &dns.Server{Addr: s.Addr(),
		Net:          "udp",
		Handler:      udpHandler,
		UDPSize:      65535,
		ReadTimeout:  s.rTimeout,
		WriteTimeout: s.wTimeout,
	}

	go s.start(udpServer)
	go s.start(tcpServer)

}
開發者ID:netroby,項目名稱:dnscache,代碼行數:33,代碼來源:server.go

示例2: Run

func (s *Server) Run() {

	Handler := NewHandler()

	tcpHandler := dns.NewServeMux()
	tcpHandler.HandleFunc(".", Handler.DoTCP)

	udpHandler := dns.NewServeMux()
	udpHandler.HandleFunc(".", Handler.DoUDP)

	tcpServer := &dns.Server{Addr: s.Addr(),
		Net:          "tcp",
		Handler:      tcpHandler,
		ReadTimeout:  s.rTimeout,
		WriteTimeout: s.wTimeout}

	udpServer := &dns.Server{Addr: s.Addr(),
		Net:          "udp",
		Handler:      udpHandler,
		UDPSize:      65535,
		ReadTimeout:  s.rTimeout,
		WriteTimeout: s.wTimeout}

	go s.start(udpServer)
	go s.start(tcpServer)

}
開發者ID:iexploree,項目名稱:godns,代碼行數:27,代碼來源:server.go

示例3: Run

func (s *Server) Run() {

	tcpResponseTimer := metrics.NewTimer()
	metrics.Register("request.handler.tcp.response_time", tcpResponseTimer)
	tcpRequestCounter := metrics.NewCounter()
	metrics.Register("request.handler.tcp.requests", tcpRequestCounter)
	tcpAcceptCounter := metrics.NewCounter()
	metrics.Register("request.handler.tcp.filter_accepts", tcpAcceptCounter)
	tcpRejectCounter := metrics.NewCounter()
	metrics.Register("request.handler.tcp.filter_rejects", tcpRejectCounter)

	udpResponseTimer := metrics.NewTimer()
	metrics.Register("request.handler.udp.response_time", udpResponseTimer)
	udpRequestCounter := metrics.NewCounter()
	metrics.Register("request.handler.udp.requests", udpRequestCounter)
	udpAcceptCounter := metrics.NewCounter()
	metrics.Register("request.handler.udp.filter_accepts", udpAcceptCounter)
	udpRejectCounter := metrics.NewCounter()
	metrics.Register("request.handler.udp.filter_rejects", udpRejectCounter)

	resolver := Resolver{etcd: s.etcd, defaultTtl: s.defaultTtl, etcdPrefix: s.prefix}
	tcpDNShandler := &Handler{
		resolver:       &resolver,
		requestCounter: tcpRequestCounter,
		acceptCounter:  tcpAcceptCounter,
		rejectCounter:  tcpRejectCounter,
		responseTimer:  tcpResponseTimer,
		queryFilterer:  s.queryFilterer}
	udpDNShandler := &Handler{
		resolver:       &resolver,
		requestCounter: udpRequestCounter,
		acceptCounter:  udpAcceptCounter,
		rejectCounter:  udpRejectCounter,
		responseTimer:  udpResponseTimer,
		queryFilterer:  s.queryFilterer}

	udpHandler := dns.NewServeMux()
	tcpHandler := dns.NewServeMux()

	tcpHandler.HandleFunc(".", tcpDNShandler.Handle)
	udpHandler.HandleFunc(".", udpDNShandler.Handle)

	tcpServer := &dns.Server{Addr: s.Addr(),
		Net:          "tcp",
		Handler:      tcpHandler,
		ReadTimeout:  s.rTimeout,
		WriteTimeout: s.wTimeout}

	udpServer := &dns.Server{Addr: s.Addr(),
		Net:          "udp",
		Handler:      udpHandler,
		UDPSize:      65535,
		ReadTimeout:  s.rTimeout,
		WriteTimeout: s.wTimeout}

	go s.start(udpServer)
	go s.start(tcpServer)
}
開發者ID:brk0v,項目名稱:discodns,代碼行數:58,代碼來源:server.go

示例4: Run

// Run is a blocking operation that starts the server listening on the DNS ports.
func (s *server) Run() error {
	mux := dns.NewServeMux()
	mux.Handle(".", s)

	dnsReadyMsg := func(addr, net string) {
		if s.config.DNSSEC == "" {
			log.Printf("skydns: ready for queries on %s for %s://%s [rcache %d]", s.config.Domain, net, addr, s.config.RCache)
		} else {
			log.Printf("skydns: ready for queries on %s for %s://%s [rcache %d], signing with %s [scache %d]", s.config.Domain, net, addr, s.config.RCache, s.config.DNSSEC, s.config.SCache)
		}
	}

	s.group.Add(1)
	go func() {
		defer s.group.Done()
		if err := dns.ListenAndServe(s.config.DnsAddr, s.dnsTCPclient.Net, mux); err != nil {
			log.Fatalf("skydns: %s", err)
		}
	}()
	dnsReadyMsg(s.config.DnsAddr, s.dnsTCPclient.Net)
	s.group.Add(1)
	go func() {
		defer s.group.Done()
		if err := dns.ListenAndServe(s.config.DnsAddr, s.dnsUDPclient.Net, mux); err != nil {
			log.Fatalf("skydns: %s", err)
		}
	}()
	dnsReadyMsg(s.config.DnsAddr, s.dnsUDPclient.Net)

	s.group.Wait()
	return nil
}
開發者ID:jhadvig,項目名稱:origin,代碼行數:33,代碼來源:server.go

示例5: createMux

func (d *DNSServer) createMux(client *dns.Client, defaultMaxResponseSize int) *dns.ServeMux {
	m := dns.NewServeMux()
	m.HandleFunc(d.domain, d.handleLocal(defaultMaxResponseSize))
	m.HandleFunc(reverseDNSdomain, d.handleReverse(client, defaultMaxResponseSize))
	m.HandleFunc(topDomain, d.handleRecursive(client, defaultMaxResponseSize))
	return m
}
開發者ID:jimmy777,項目名稱:weave,代碼行數:7,代碼來源:dns.go

示例6: ListenAndServe

func (srv *DNSServer) ListenAndServe() error {
	if srv.GetStore() == nil {
		panic("missing Store")
	}
	if srv.Domain == "" {
		srv.Domain = dnsDomain
	}
	if err := srv.validateRecursors(); err != nil {
		return err
	}

	api := dnsAPI{srv}
	mux := dns.NewServeMux()
	mux.HandleFunc(srv.Domain, api.ServiceLookup)
	if len(srv.Recursors) > 0 {
		mux.HandleFunc(".", api.Recurse)
	}

	errors := make(chan error, 4)
	done := func() { errors <- nil }

	if srv.UDPAddr != "" {
		l, err := reuseport.NewReusablePortPacketConn("udp4", srv.UDPAddr)
		if err != nil {
			return err
		}
		srv.UDPAddr = l.(*net.UDPConn).LocalAddr().String()
		server := &dns.Server{
			Net:               "udp",
			PacketConn:        l,
			Handler:           mux,
			NotifyStartedFunc: done,
		}
		go func() { errors <- server.ActivateAndServe() }()
		srv.servers = append(srv.servers, server)
	}

	if srv.TCPAddr != "" {
		l, err := keepalive.ReusableListen("tcp4", srv.TCPAddr)
		if err != nil {
			return err
		}
		srv.TCPAddr = l.Addr().String()
		server := &dns.Server{
			Net:               "tcp",
			Listener:          l,
			Handler:           mux,
			NotifyStartedFunc: done,
		}
		go func() { errors <- server.ActivateAndServe() }()
		srv.servers = append(srv.servers, server)
	}

	for range srv.servers {
		if err := <-errors; err != nil {
			return err
		}
	}
	return nil
}
開發者ID:ably-forks,項目名稱:flynn,代碼行數:60,代碼來源:dns.go

示例7: Start

// Start the mDNS server
func (s *MDNSServer) Start(ifi *net.Interface) (err error) {
	// skip double initialization
	if s.running {
		return nil
	}

	// This is a bit of a kludge - per the RFC we should send responses from 5353, but that doesn't seem to work
	s.sendconn, err = net.ListenUDP("udp4", &net.UDPAddr{IP: net.IPv4zero, Port: 0})
	if err != nil {
		return err
	}

	conn, err := LinkLocalMulticastListener(ifi)
	if err != nil {
		return err
	}

	if ifi == nil {
		s.localAddrs, err = net.InterfaceAddrs()
	} else {
		s.localAddrs, err = ifi.Addrs()
	}
	if err != nil {
		return err
	}

	handleLocal := s.makeHandler(dns.TypeA,
		func(zone ZoneLookup, r *dns.Msg, q *dns.Question) *dns.Msg {
			if ips, err := zone.LookupName(q.Name); err == nil {
				return makeAddressReply(r, q, ips)
			}
			return nil
		})

	handleReverse := s.makeHandler(dns.TypePTR,
		func(zone ZoneLookup, r *dns.Msg, q *dns.Question) *dns.Msg {
			if names, err := zone.LookupInaddr(q.Name); err == nil {
				return makePTRReply(r, q, names)
			}
			return nil
		})

	mux := dns.NewServeMux()
	mux.HandleFunc(s.zone.Domain(), handleLocal)
	mux.HandleFunc(RDNSDomain, handleReverse)

	s.srv = &dns.Server{
		Listener:   nil,
		PacketConn: conn,
		Handler:    mux,
	}
	go s.srv.ActivateAndServe()
	s.running = true
	return err
}
開發者ID:grkvlt,項目名稱:weave,代碼行數:56,代碼來源:mdns_server.go

示例8: Run

// Run is a blocking operation that starts the server listening on the DNS ports.
func (s *server) Run() error {
	mux := dns.NewServeMux()
	mux.Handle(".", s)

	s.group.Add(2)
	go runDNSServer(s.group, mux, "tcp", s.config.DnsAddr, s.config.ReadTimeout)
	go runDNSServer(s.group, mux, "udp", s.config.DnsAddr, s.config.ReadTimeout)

	s.group.Wait()
	return nil
}
開發者ID:jonboulle,項目名稱:skydns2,代碼行數:12,代碼來源:server.go

示例9: createMux

func (d *DNSServer) createMux(client *dns.Client, defaultMaxResponseSize int) *dns.ServeMux {
	m := dns.NewServeMux()
	h := &handler{
		DNSServer:       d,
		maxResponseSize: defaultMaxResponseSize,
		client:          client,
	}
	m.HandleFunc(d.domain, h.handleLocal)
	m.HandleFunc(reverseDNSdomain, h.handleReverse)
	m.HandleFunc(topDomain, h.handleRecursive)
	return m
}
開發者ID:n054,項目名稱:weave,代碼行數:12,代碼來源:dns.go

示例10: Start

func (s *Server) Start() error {
	s.mux = dns.NewServeMux()
	s.mux.Handle(".", s.engine)

	s.wgStart.Add(2)
	s.udpListener = s.runListener("udp")
	s.tcpListener = s.runListener("tcp")
	s.wgStart.Wait()

	log.Info("Listeners started")
	return nil
}
開發者ID:JeremyRand,項目名稱:ncdns,代碼行數:12,代碼來源:server.go

示例11: Run

// Run is a blocking operation that starts the server listening on the DNS ports.
func (s *server) Run() error {
	mux := dns.NewServeMux()
	mux.Handle(".", s)

	s.group.Add(2)
	go runDNSServer(s.group, mux, "tcp", s.config.DnsAddr, s.config.ReadTimeout)
	go runDNSServer(s.group, mux, "udp", s.config.DnsAddr, s.config.ReadTimeout)
	s.config.log.Printf("connected to etcd cluster at %s", machines)

	s.group.Wait()
	return nil
}
開發者ID:njhartwell,項目名稱:skydns2,代碼行數:13,代碼來源:server.go

示例12: NewServer

// Newserver returns a new Server.
func NewServer(members []string, domain string, dnsAddr string, httpAddr string, dataDir string, rt, wt time.Duration, secret string, nameservers []string, roundrobin bool, tlskey string, tlspem string) (s *Server) {
	s = &Server{
		members:      members,
		domain:       strings.ToLower(domain),
		domainLabels: dns.CountLabel(dns.Fqdn(domain)),
		dnsAddr:      dnsAddr,
		httpAddr:     httpAddr,
		readTimeout:  rt,
		writeTimeout: wt,
		router:       mux.NewRouter(),
		registry:     registry.New(),
		dataDir:      dataDir,
		dnsHandler:   dns.NewServeMux(),
		waiter:       new(sync.WaitGroup),
		secret:       secret,
		nameservers:  nameservers,
		roundrobin:   roundrobin,
		tlskey:       tlskey,
		tlspem:       tlspem,
	}

	if _, err := os.Stat(s.dataDir); os.IsNotExist(err) {
		log.Fatal("Data directory does not exist: ", dataDir)
		return
	}

	// DNS
	s.dnsHandler.Handle(".", s)

	authWrapper := s.authHTTPWrapper

	// API Routes
	s.router.HandleFunc("/skydns/services/{uuid}", authWrapper(s.addServiceHTTPHandler)).Methods("PUT")
	s.router.HandleFunc("/skydns/services/{uuid}", authWrapper(s.getServiceHTTPHandler)).Methods("GET")
	s.router.HandleFunc("/skydns/services/{uuid}", authWrapper(s.removeServiceHTTPHandler)).Methods("DELETE")
	s.router.HandleFunc("/skydns/services/{uuid}", authWrapper(s.updateServiceHTTPHandler)).Methods("PATCH")

	s.router.HandleFunc("/skydns/callbacks/{uuid}", authWrapper(s.addCallbackHTTPHandler)).Methods("PUT")

	// External API Routes
	// /skydns/services #list all services
	s.router.HandleFunc("/skydns/services/", authWrapper(s.getServicesHTTPHandler)).Methods("GET")
	// /skydns/regions #list all regions
	s.router.HandleFunc("/skydns/regions/", authWrapper(s.getRegionsHTTPHandler)).Methods("GET")
	// /skydns/environnments #list all environments
	s.router.HandleFunc("/skydns/environments/", authWrapper(s.getEnvironmentsHTTPHandler)).Methods("GET")

	// Raft Routes
	s.router.HandleFunc("/raft/join", s.joinHandler).Methods("POST")
	return
}
開發者ID:nettedfish,項目名稱:skydns1,代碼行數:52,代碼來源:server.go

示例13: Run

// Run is a blocking operation that starts the server listening on the DNS ports
func (s *server) Run() error {
	var (
		group = &sync.WaitGroup{}
		mux   = dns.NewServeMux()
	)
	mux.Handle(".", s)

	group.Add(2)
	go runDNSServer(group, mux, "tcp", s.config.DnsAddr, 0, s.config.WriteTimeout, s.config.ReadTimeout)
	go runDNSServer(group, mux, "udp", s.config.DnsAddr, 0, s.config.WriteTimeout, s.config.ReadTimeout)

	group.Wait()
	return nil
}
開發者ID:wangfakang,項目名稱:skydns2,代碼行數:15,代碼來源:server.go

示例14: Run

func (s *Server) Run() (err error) {
	hndlr := handler.NewHandler(s.Timeout, s.Interval)

	tcpHandler := dns.NewServeMux()
	tcpHandler.HandleFunc(".", hndlr.HandleTcp)
	tcpServer := &dns.Server{
		Addr:         s.Addr(),
		Net:          "tcp",
		Handler:      tcpHandler,
		ReadTimeout:  s.Timeout,
		WriteTimeout: s.Timeout,
	}
	go func() {
		err := tcpServer.ListenAndServe()
		if err != nil {
			panic(err)
		}
	}()

	udpHandler := dns.NewServeMux()
	udpHandler.HandleFunc(".", hndlr.HandleUdp)
	udpServer := &dns.Server{
		Addr:         s.Addr(),
		Net:          "udp",
		Handler:      udpHandler,
		ReadTimeout:  s.Timeout,
		WriteTimeout: s.Timeout,
	}
	go func() {
		err := udpServer.ListenAndServe()
		if err != nil {
			panic(err)
		}
	}()

	return
}
開發者ID:pritunl,項目名稱:pritunl-dns,代碼行數:37,代碼來源:server.go

示例15: NewServer

// Newserver returns a new server.
// TODO(miek): multiple ectdAddrs
func NewServer(domain, dnsAddr string, nameservers []string, etcdAddr string) *server {
	s := &server{
		domain:       dns.Fqdn(strings.ToLower(domain)),
		domainLabels: dns.CountLabel(dns.Fqdn(domain)),
		DnsAddr:      dnsAddr,
		client:       etcd.NewClient([]string{etcdAddr}),
		dnsHandler:   dns.NewServeMux(),
		waiter:       new(sync.WaitGroup),
		nameservers:  nameservers,
	}

	// DNS
	s.dnsHandler.Handle(".", s)
	return s
}
開發者ID:jkingyens,項目名稱:skydns2,代碼行數:17,代碼來源:server.go


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