feat: 使用 net.Listen 获取服务器实际监听地址 - #5
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
背景
http.ListenAndServe无法在:0时获取系统分配的真实端口,也无法准确输出实际监听地址变更
cmd/server/main.go: 将http.ListenAndServe替换为net.Listen+http.Servelistener.Addr().String()获取真实监听地址并打印-addr :0时系统自动分配端口并正确输出行为影响
-addr :0时能看到系统分配的实际端口号风险和回滚
验证
gofmt -e通过备注
cmd/server/main.go改动,新增netimport,移除未使用的间接依赖