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
29a9c6f1
Commit
29a9c6f1
authored
Nov 05, 2014
by
Juan Batiz-Benet
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
net: added InterfaceMultiaddrs
parent
76ea093a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
10 deletions
+20
-10
multiaddr.go
multiaddr.go
+20
-10
No files found.
multiaddr.go
View file @
29a9c6f1
...
@@ -7,17 +7,15 @@ import (
...
@@ -7,17 +7,15 @@ import (
"os"
"os"
ma
"github.com/jbenet/go-multiaddr"
ma
"github.com/jbenet/go-multiaddr"
manet
"github.com/jbenet/go-multiaddr/net"
)
)
var
usage
=
`multiaddr conversion
var
formats
=
[]
string
{
"string"
,
"bytes"
,
"hex"
,
"slice"
}
usage: multiaddr [fmt] <>`
var
formats
=
[]
string
{
"string"
,
"bytes"
,
"hex"
,
"raw"
}
var
format
string
var
format
string
func
init
()
{
func
init
()
{
flag
.
Usage
=
func
()
{
flag
.
Usage
=
func
()
{
fmt
.
Fprintf
(
os
.
Stderr
,
"usage: %s <multiaddr>
\n\n
Flags:
\n
"
,
os
.
Args
[
0
])
fmt
.
Fprintf
(
os
.
Stderr
,
"usage: %s
[
<multiaddr>
]
\n\n
Flags:
\n
"
,
os
.
Args
[
0
])
flag
.
PrintDefaults
()
flag
.
PrintDefaults
()
}
}
...
@@ -29,8 +27,14 @@ func init() {
...
@@ -29,8 +27,14 @@ func init() {
func
main
()
{
func
main
()
{
flag
.
Parse
()
flag
.
Parse
()
args
:=
flag
.
Args
()
args
:=
flag
.
Args
()
if
len
(
args
)
!=
1
{
if
len
(
args
)
==
0
{
die
(
"error: can only take one argument"
)
maddrs
,
err
:=
manet
.
InterfaceMultiaddrs
()
if
err
!=
nil
{
die
(
err
)
}
output
(
maddrs
...
)
return
}
}
m
,
err
:=
ma
.
NewMultiaddr
(
args
[
0
])
m
,
err
:=
ma
.
NewMultiaddr
(
args
[
0
])
...
@@ -38,16 +42,22 @@ func main() {
...
@@ -38,16 +42,22 @@ func main() {
die
(
err
)
die
(
err
)
}
}
fmt
.
Println
(
outfmt
(
m
))
output
(
m
)
}
func
output
(
ms
...
ma
.
Multiaddr
)
{
for
_
,
m
:=
range
ms
{
fmt
.
Println
(
outfmt
(
m
))
}
}
}
func
outfmt
(
m
ma
.
Multiaddr
)
string
{
func
outfmt
(
m
ma
.
Multiaddr
)
string
{
switch
format
{
switch
format
{
case
"string"
:
case
"string"
:
return
m
.
String
()
return
m
.
String
()
case
"
bytes
"
:
case
"
slice
"
:
return
fmt
.
Sprintf
(
"%v"
,
m
.
Bytes
())
return
fmt
.
Sprintf
(
"%v"
,
m
.
Bytes
())
case
"
raw
"
:
case
"
bytes
"
:
return
string
(
m
.
Bytes
())
return
string
(
m
.
Bytes
())
case
"hex"
:
case
"hex"
:
return
"0x"
+
hex
.
EncodeToString
(
m
.
Bytes
())
return
"0x"
+
hex
.
EncodeToString
(
m
.
Bytes
())
...
...
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