ListenAndServe返回net.DNSError“提供的nodename和servname”

时间:2017-06-19 09:33:19

标签: http docker go


我正在尝试编写一个go http服务器,但是当我尝试收听传入的连接时,我遇到了问题。
硬件设置:MacOS Sierra 10.12.4,docker 17.03
我有一个将打开的yml文件。 phpmyadmin和sql:

mysql:
  extends:
    service: mysql-5.7
  ports:
    - "3306:3306"
phpmyadmin:
  image: phpmyadmin/phpmyadmin:latest
  links:
  - "mysql:db"
  ports:
  - "8080:80"

这似乎工作正常。 在此之后,我写了一个go文件来连接和监听连接:

stack := negroni.New()
stack.Use(cors.New(cors.Options{
    AllowedOrigins:   []string{"*"},
    AllowedMethods:   []string{"GET", "POST", "PUT", "DELETE"},
    AllowedHeaders:   []string{"*"},
    AllowCredentials: true,
}))

external := &http.Server{
    Addr:    "10001",
    Handler: stack,
}

// Start the server, listening for incomming connections.
go func() {
    err = external.ListenAndServe()
    if err != nil && err != http.ErrServerClosed {
        level.Error(logger).Log("msg", "error while listening", "err", err)
        os.Exit(1)
    }
}()

这将产生错误:

  

level =错误时间= 2017-06-19T09:28:14.726843314Z app =“Falbala”env = local pid = 1084 host = P5RO-PORT367.local msg =“收听时出错”err =“listen tcp:lookup tcp / 10001“:提供了nodename或servname,或者未知”

任何想法?
谢谢

1 个答案:

答案 0 :(得分:0)

documentation,地址值应为字符串。

// ListenAndServe always returns a non-nil error.
func ListenAndServe(addr string, handler Handler) error {
    server := &Server{Addr: addr, Handler: handler}
    return server.ListenAndServe()
}

你能试试吗?

external := http.Server{
    Addr:    ":10001",
    Handler: stack,
}