本文整理匯總了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)
}
示例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)
}
示例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)
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}