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 ":"?

为什么port是字符串而不是整数?
- 写回答
- 好问题 0 提建议
- 关注问题
- 邀请回答
-
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.本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报