File tree 1 file changed +10
-3
lines changed
1 file changed +10
-3
lines changed Original file line number Diff line number Diff line change 6
6
"log"
7
7
"net"
8
8
"net/http"
9
+ "regexp"
9
10
"strings"
10
11
11
12
"github.com/libp2p/go-libp2p"
@@ -125,18 +126,24 @@ func ExampleHost_overLibp2pStreams() {
125
126
// Output: Hello HTTP
126
127
}
127
128
129
+ var tcpPortRE = regexp .MustCompile (`/tcp/(\d+)` )
130
+
128
131
func ExampleHost_Serve () {
129
132
server := libp2phttp.Host {
130
133
InsecureAllowHTTP : true , // For our example, we'll allow insecure HTTP
131
- ListenAddrs : []ma.Multiaddr {ma .StringCast ("/ip4/127.0.0.1/tcp/50221 /http" )},
134
+ ListenAddrs : []ma.Multiaddr {ma .StringCast ("/ip4/127.0.0.1/tcp/0 /http" )},
132
135
}
133
136
134
137
go server .Serve ()
135
138
defer server .Close ()
136
139
137
- fmt .Println (server .Addrs ())
140
+ for _ , a := range server .Addrs () {
141
+ s := a .String ()
142
+ addrWithoutSpecificPort := tcpPortRE .ReplaceAllString (s , "/tcp/<runtime-port>" )
143
+ fmt .Println (addrWithoutSpecificPort )
144
+ }
138
145
139
- // Output: [ /ip4/127.0.0.1/tcp/50221 /http]
146
+ // Output: /ip4/127.0.0.1/tcp/<runtime-port> /http
140
147
}
141
148
142
149
func ExampleHost_SetHTTPHandler () {
You can’t perform that action at this time.
0 commit comments