Skip to content

Commit c06957d

Browse files
committed
net/addr: fix URL function
1 parent 7623f45 commit c06957d

2 files changed

Lines changed: 17 additions & 5 deletions

File tree

net/addr.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,7 @@ func (a Addr) String() string {
6060

6161
// URL formats the scheme with address and with the optional port.
6262
func (a Addr) URL() string {
63-
u := url.URL{
64-
Scheme: a.scheme,
65-
Host: a.String(),
66-
}
67-
return u.String()
63+
return a.scheme + "://" + a.String()
6864
}
6965

7066
// RemovePort sets the zero value.

net/addr_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package net
2+
3+
import (
4+
"testing"
5+
6+
"github.com/stretchr/testify/assert"
7+
"github.com/stretchr/testify/require"
8+
)
9+
10+
func TestParseString(t *testing.T) {
11+
ip6 := "[fe80::6262:3c03:5549:6ad6%eno1]:34786"
12+
schema := "coap"
13+
v, err := ParseString(schema, ip6)
14+
require.NoError(t, err)
15+
assert.Equal(t, schema+"://"+ip6, v.URL())
16+
}

0 commit comments

Comments
 (0)