doufenpaiyu63706 2017-12-27 12:47
浏览 98
已采纳

为什么port是字符串而不是整数?

The Port method returns a string and not an integer. What is the reason for that and is it safe to prefix the port with ":"?

  • 写回答

2条回答 默认 最新

  • dthjnc306679 2017-12-27 13:10
    关注

    This is because what appears after the colon can be either a port number or service name.

    The following is a valid example where the service name is used instead of a port number:

    listener, err := net.Listen("tcp", "localhost:https") // port 443
    // ...
    

    The port mapping for a particular service can be looked up using net.LookupPort. On Unix systems, the /etc/services file is sourced for the mappings.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?