dongqigu0429
2017-06-19 09:33
浏览 52

ListenAndServe返回net.DNSError“提供了节点名或服务名”


I am trying to write a go http server but I have an issue when I try to listen to incoming connections.
HW setup: MacOS Sierra 10.12.4, docker 17.03
I have a yml file that will open a . phpmyadmin and sql:

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

This seems to work fine. After this I wrote a go file to connect and listen to connections:

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)
    }
}()

This will generate the error:

level=error time=2017-06-19T09:28:14.726843314Z app=“Falbala” env=local pid=1084 host=P5RO-PORT367.local msg="error while listening" err="listen tcp: lookup tcp/10001”: nodename nor servname provided, or not known"

Any ideas?
Thank you

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • duanliaogui4133 2017-06-19 09:43
    已采纳

    From the documentation, address value should be a string.

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

    Can you try?

    external := http.Server{
        Addr:    ":10001",
        Handler: stack,
    }
    
    打赏 评论

相关推荐 更多相似问题