本文整理汇总了Golang中github.com/miekg/dns.Server.ListenAndServe方法的典型用法代码示例。如果您正苦于以下问题:Golang Server.ListenAndServe方法的具体用法?Golang Server.ListenAndServe怎么用?Golang Server.ListenAndServe使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/miekg/dns.Server
的用法示例。
在下文中一共展示了Server.ListenAndServe方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: main
func main() {
flag.Parse()
log.SetOutput(os.Stdout)
log.SetLevel(log.DebugLevel)
var client *docker.Client
if os.Getenv("DOCKER_HOST") != "" {
var err error
certPath := os.Getenv("DOCKER_CERT_PATH")
client, err = docker.NewTLSClient(os.Getenv("DOCKER_HOST"), path.Join(certPath, "cert.pem"), path.Join(certPath, "key.pem"), path.Join(certPath, "ca.pem"))
if err != nil {
log.Fatal(err)
}
} else {
var err error
client, err = docker.NewClient("unix:///var/run/docker.sock")
if err != nil {
log.Fatal(err)
}
}
handler := Handler{docker: client, domain: fmt.Sprintf("%s.", *domain)}
server := dns.Server{}
server.Handler = &handler
server.Net = *network
server.Addr = *addr
err := server.ListenAndServe()
if err != nil {
log.Fatal(err)
}
}
示例2: start
func (s *Server) start(ds *dns.Server) {
log.Printf("start %s listener on %s\n", ds.Net, s.Addr())
err := ds.ListenAndServe()
if err != nil {
log.Printf("start %s listener on %s failed:%s\n", ds.Net, s.Addr(), err.Error())
}
}
示例3: runDNSServer
func runDNSServer(server *dns.Server, errc chan error) {
logger.Printf("DNS/%s listening on %s\n", server.Net, server.Addr)
errc <- fmt.Errorf(
"[error] DNS/%s - server failed: %s", server.Net,
server.ListenAndServe(),
)
}
示例4: Run
func (ds *DjdnsServer) Run(addr string) error {
server := new(dns.Server)
server.Addr = addr
server.Net = "udp"
server.Handler = ds
return server.ListenAndServe()
}
示例5: start
func (s *Server) start(ds *dns.Server) {
log.Infof("Start %s listener on %s", ds.Net, s.Addr())
err := ds.ListenAndServe()
if err != nil {
log.Fatalf("Start %s listener on %s failed: %s", ds.Net, s.Addr(), err.Error())
}
}
示例6: start
func (s *Server) start(ds *dns.Server) {
fmt.Println("Start listener on ", ds.Net, ":", s.Addr())
err := ds.ListenAndServe()
if err != nil {
fmt.Println("Start listener failed:", ds.Net, ":", s.Addr(), err.Error())
}
}
示例7: main
func main() {
log.SetFlags(log.Flags() | log.Lmicroseconds)
flag.Usage = func() {
fmt.Fprintln(os.Stderr, "Arguments:")
flag.PrintDefaults()
fmt.Fprint(os.Stderr, logFormatExample)
}
flag.Parse()
dns.HandleFunc(".", serve)
server := dns.Server{Addr: *flListen, Net: "udp"}
err := server.ListenAndServe()
eexit(err)
}
示例8: start
func start(ctx *cli.Context) {
addr := fmt.Sprintf(":%d", ctx.Int("port"))
net := "udp"
if ctx.Bool("tcp") {
net = "tcp"
}
handler := BaDNSHandler{hostPrefix: ctx.String("host-prefix")}
enableGlitches(ctx, &handler)
server := dns.Server{Addr: addr, Net: net, Handler: handler}
if err := server.ListenAndServe(); err != nil {
log.Fatal("Failed to start the server", err)
}
}
示例9: dnsServices
func dnsServices() {
if *dnsBinding == "" {
return
}
log.Printf("Starting DNS services on %v.", *dnsBinding)
d := dnsService{}
serv := dns.Server{
Net: "udp",
Addr: *dnsBinding,
Handler: d,
}
err := serv.ListenAndServe()
if err != nil {
log.Fatalf("DNS server failure: %v", err)
}
}
示例10: doRunListener
func (s *Server) doRunListener(ds *dns.Server) {
err := ds.ListenAndServe()
log.Fatale(err)
}