mirror of
https://github.com/go-kratos/kratos.git
synced 2025-03-25 21:38:59 +02:00
fix bug of host.Extract (#1481)
This commit is contained in:
parent
24ec23f0e4
commit
2ce8f22fac
@ -36,7 +36,7 @@ func Port(lis net.Listener) (int, bool) {
|
||||
// Extract returns a private addr and port.
|
||||
func Extract(hostPort string, lis net.Listener) (string, error) {
|
||||
addr, port, err := net.SplitHostPort(hostPort)
|
||||
if err != nil {
|
||||
if err != nil && lis == nil {
|
||||
return "", err
|
||||
}
|
||||
if lis != nil {
|
||||
|
@ -76,6 +76,13 @@ func TestExtract(t *testing.T) {
|
||||
}
|
||||
})
|
||||
}
|
||||
lis, err := net.Listen("tcp", ":12345")
|
||||
assert.NoError(t, err)
|
||||
res, err := Extract("", lis)
|
||||
assert.NoError(t, err)
|
||||
expect, err := Extract(lis.Addr().String(), nil)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, expect, res)
|
||||
}
|
||||
|
||||
func TestExtract2(t *testing.T) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user