Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
mf
go-multiaddr
Commits
7768f965
Unverified
Commit
7768f965
authored
Jan 10, 2022
by
Marten Seemann
Committed by
GitHub
Jan 10, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add a Contains function (#172)
parent
f9011923
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
0 deletions
+23
-0
multiaddr.go
multiaddr.go
+10
-0
multiaddr_test.go
multiaddr_test.go
+13
-0
No files found.
multiaddr.go
View file @
7768f965
...
...
@@ -200,3 +200,13 @@ addrloop:
}
return
b
}
// Contains reports whether addr is contained in addrs.
func
Contains
(
addrs
[]
Multiaddr
,
addr
Multiaddr
)
bool
{
for
_
,
a
:=
range
addrs
{
if
addr
.
Equal
(
a
)
{
return
true
}
}
return
false
}
multiaddr_test.go
View file @
7768f965
...
...
@@ -762,3 +762,16 @@ func TestFilterAddrs(t *testing.T) {
require
.
ElementsMatch
(
t
,
FilterAddrs
(
good
,
filter
),
good
)
require
.
ElementsMatch
(
t
,
FilterAddrs
(
goodAndBad
,
filter
),
good
)
}
func
TestContains
(
t
*
testing
.
T
)
{
a1
:=
newMultiaddr
(
t
,
"/ip4/127.0.0.1/tcp/1234"
)
a2
:=
newMultiaddr
(
t
,
"/ip4/1.1.1.1/tcp/999"
)
a3
:=
newMultiaddr
(
t
,
"/ip4/1.2.3.4/udp/443/quic"
)
addrs
:=
[]
Multiaddr
{
a1
,
a2
,
a3
}
require
.
True
(
t
,
Contains
(
addrs
,
a1
))
require
.
True
(
t
,
Contains
(
addrs
,
a2
))
require
.
True
(
t
,
Contains
(
addrs
,
a3
))
require
.
False
(
t
,
Contains
(
addrs
,
newMultiaddr
(
t
,
"/ip4/4.3.2.1/udp/1234/utp"
)))
require
.
False
(
t
,
Contains
(
nil
,
a1
))
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment