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
1ec9436b
Commit
1ec9436b
authored
Oct 06, 2014
by
Juan Batiz-Benet
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
docs
parent
c90ef447
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
56 additions
and
18 deletions
+56
-18
README.md
README.md
+20
-18
doc.go
doc.go
+36
-0
No files found.
README.md
View file @
1ec9436b
...
@@ -7,18 +7,20 @@
...
@@ -7,18 +7,20 @@
### Simple
### Simple
```
go
```
go
import
"github.com/jbenet/go-multiaddr"
import
ma
"github.com/jbenet/go-multiaddr"
m
:=
multiaddr
.
NewMultiaddr
(
"/ip4/127.0.0.1/udp/1234"
)
// construct from a string (err signals parse failure)
// <Multiaddr /ip4/127.0.0.1/udp/1234>
m1
,
err
:=
ma
.
NewMultiaddr
(
"/ip4/127.0.0.1/udp/1234"
)
m
.
buffer
// <Buffer >
m
.
String
()
// /ip4/127.0.0.1/udp/1234
// construct with Buffer
// construct from bytes (err signals parse failure)
m
=
multiaddr
.
Multiaddr
{
Bytes
:
m
.
Bytes
}
m2
,
err
:=
ma
.
NewMultiaddrBytes
(
m1
.
Bytes
())
// <Multiaddr /ip4/127.0.0.1/udp/1234>
// true
strings
.
Equal
(
m1
.
String
(),
"/ip4/127.0.0.1/udp/1234"
)
strings
.
Equal
(
m1
.
String
(),
m2
.
String
())
bytes
.
Equal
(
m1
.
Bytes
(),
m2
.
Bytes
())
m1
.
Equal
(
m2
)
m2
.
Equal
(
m1
)
```
```
### Protocols
### Protocols
...
@@ -36,7 +38,7 @@ addr.Protocols()
...
@@ -36,7 +38,7 @@ addr.Protocols()
```
go
```
go
// handles the stupid url version too
// handles the stupid url version too
m
=
m
ultiaddr
.
NewUrl
(
"udp4://127.0.0.1:1234"
)
m
=
m
a
.
NewUrl
(
"udp4://127.0.0.1:1234"
)
// <Multiaddr /ip4/127.0.0.1/udp/1234>
// <Multiaddr /ip4/127.0.0.1/udp/1234>
m
.
Url
(
buf
)
m
.
Url
(
buf
)
// udp4://127.0.0.1:1234
// udp4://127.0.0.1:1234
...
@@ -45,9 +47,9 @@ m.Url(buf)
...
@@ -45,9 +47,9 @@ m.Url(buf)
### En/decapsulate
### En/decapsulate
```
go
```
go
m
.
Encapsulate
(
m
.
NewMultiaddr
(
"/sctp/5678"
))
m
.
Encapsulate
(
m
a
.
NewMultiaddr
(
"/sctp/5678"
))
// <Multiaddr /ip4/127.0.0.1/udp/1234/sctp/5678>
// <Multiaddr /ip4/127.0.0.1/udp/1234/sctp/5678>
m
.
Decapsulate
(
m
.
NewMultiaddr
(
"/udp"
))
// up to + inc last occurrence of subaddr
m
.
Decapsulate
(
m
a
.
NewMultiaddr
(
"/udp"
))
// up to + inc last occurrence of subaddr
// <Multiaddr /ip4/127.0.0.1>
// <Multiaddr /ip4/127.0.0.1>
```
```
...
@@ -56,11 +58,11 @@ m.Decapsulate(m.NewMultiaddr("/udp")) // up to + inc last occurrence of subaddr
...
@@ -56,11 +58,11 @@ m.Decapsulate(m.NewMultiaddr("/udp")) // up to + inc last occurrence of subaddr
Multiaddr allows expressing tunnels very nicely.
Multiaddr allows expressing tunnels very nicely.
```
js
```
js
printer
:
=
m
ultiaddr
.
NewMultiaddr
(
"
/ip4/192.168.0.13/tcp/80
"
)
printer
,
_
:
=
m
a
.
NewMultiaddr
(
"
/ip4/192.168.0.13/tcp/80
"
)
proxy
:
=
m
ultiaddr
.
NewMultiaddr
(
"
/ip4/10.20.30.40/tcp/443
"
)
proxy
,
_
:
=
m
a
.
NewMultiaddr
(
"
/ip4/10.20.30.40/tcp/443
"
)
printerOverProxy
:
=
proxy
.
Encapsulate
(
printer
)
printerOverProxy
:
=
proxy
.
Encapsulate
(
printer
)
//
<Multiaddr
/ip4/10.20.30.40/tcp/443/ip4/192.168.0.13/tcp/80
>
// /ip4/10.20.30.40/tcp/443/ip4/192.168.0.13/tcp/80
proxyAgain
:
=
printerOverProxy
.
Decapsulate
(
multiaddr
.
NewMultiaddr
(
"
/ip4
"
)
)
proxyAgain
:
=
printerOverProxy
.
Decapsulate
(
printer
)
//
<Multiaddr
/ip4/10.20.30.40/tcp/443
>
// /ip4/10.20.30.40/tcp/443
```
```
doc.go
0 → 100644
View file @
1ec9436b
/*
Package multiaddr provides an implementation of the Multiaddr network
address format. Multiaddr emphasizes explicitness, self-description, and
portability. It allows applications to treat addresses as opaque tokens,
and to avoid making assumptions about the address representation (e.g. length).
Learn more at https://github.com/jbenet/multiaddr
Basic Use:
import (
"bytes"
"strings"
ma "github.com/jbenet/go-multiaddr"
)
// construct from a string (err signals parse failure)
m1, err := ma.NewMultiaddr("/ip4/127.0.0.1/udp/1234")
// construct from bytes (err signals parse failure)
m2, err := ma.NewMultiaddrBytes(m1.Bytes())
// true
strings.Equal(m1.String(), "/ip4/127.0.0.1/udp/1234")
strings.Equal(m1.String(), m2.String())
bytes.Equal(m1.Bytes(), m2.Bytes())
m1.Equal(m2)
m2.Equal(m1)
// tunneling (en/decap)
printer, _ := ma.NewMultiaddr("/ip4/192.168.0.13/tcp/80")
proxy, _ := ma.NewMultiaddr("/ip4/10.20.30.40/tcp/443")
printerOverProxy := proxy.Encapsulate(printer)
proxyAgain := printerOverProxy.Decapsulate(printer)
*/
package
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