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
f05346f3
Commit
f05346f3
authored
Nov 05, 2014
by
Juan Batiz-Benet
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
hide-loopback in tool
parent
20cc417a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
29 additions
and
8 deletions
+29
-8
multiaddr/multiaddr.go
multiaddr/multiaddr.go
+29
-8
No files found.
multiaddr/multiaddr.go
View file @
f05346f3
...
...
@@ -10,8 +10,10 @@ import (
manet
"github.com/jbenet/go-multiaddr/net"
)
// flags
var
formats
=
[]
string
{
"string"
,
"bytes"
,
"hex"
,
"slice"
}
var
format
string
var
hideLoopback
bool
func
init
()
{
flag
.
Usage
=
func
()
{
...
...
@@ -22,27 +24,46 @@ func init() {
usage
:=
fmt
.
Sprintf
(
"output format, one of: %v"
,
formats
)
flag
.
StringVar
(
&
format
,
"format"
,
"string"
,
usage
)
flag
.
StringVar
(
&
format
,
"f"
,
"string"
,
usage
+
" (shorthand)"
)
flag
.
BoolVar
(
&
hideLoopback
,
"hide-loopback"
,
false
,
"do not display loopback addresses"
)
}
func
main
()
{
flag
.
Parse
()
args
:=
flag
.
Args
()
if
len
(
args
)
==
0
{
maddrs
,
err
:=
manet
.
InterfaceMultiaddrs
()
if
err
!=
nil
{
die
(
err
)
}
output
(
localAddresses
()
...
)
}
else
{
output
(
address
(
args
[
0
]))
}
}
func
localAddresses
()
[]
ma
.
Multiaddr
{
maddrs
,
err
:=
manet
.
InterfaceMultiaddrs
()
if
err
!=
nil
{
die
(
err
)
}
if
!
hideLoopback
{
return
maddrs
}
output
(
maddrs
...
)
return
var
maddrs2
[]
ma
.
Multiaddr
for
_
,
a
:=
range
maddrs
{
if
!
manet
.
IsIPLoopback
(
a
)
{
maddrs2
=
append
(
maddrs2
,
a
)
}
}
m
,
err
:=
ma
.
NewMultiaddr
(
args
[
0
])
return
maddrs2
}
func
address
(
addr
string
)
ma
.
Multiaddr
{
m
,
err
:=
ma
.
NewMultiaddr
(
addr
)
if
err
!=
nil
{
die
(
err
)
}
output
(
m
)
return
m
}
func
output
(
ms
...
ma
.
Multiaddr
)
{
...
...
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