doc.go 1.09 KB
Newer Older
Juan Batiz-Benet's avatar
docs  
Juan Batiz-Benet committed
1 2 3 4 5
/*
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).
6
Learn more at https://github.com/multiformats/multiaddr
Juan Batiz-Benet's avatar
docs  
Juan Batiz-Benet committed
7 8 9

Basic Use:

tavit ohanian's avatar
tavit ohanian committed
10 11 12 13 14
	  import (
	    "bytes"
	    "strings"
	    ma "gitlab.dms3.io/mf/go-multiaddr"
	  )
Juan Batiz-Benet's avatar
docs  
Juan Batiz-Benet committed
15

tavit ohanian's avatar
tavit ohanian committed
16 17
		// construct from a string (err signals parse failure)
		m1, err := ma.NewMultiaddr("/ip4/127.0.0.1/udp/1234")
Juan Batiz-Benet's avatar
docs  
Juan Batiz-Benet committed
18

tavit ohanian's avatar
tavit ohanian committed
19 20
		// construct from bytes (err signals parse failure)
		m2, err := ma.NewMultiaddrBytes(m1.Bytes())
Juan Batiz-Benet's avatar
docs  
Juan Batiz-Benet committed
21

tavit ohanian's avatar
tavit ohanian committed
22 23 24 25 26 27
		// 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)
Juan Batiz-Benet's avatar
docs  
Juan Batiz-Benet committed
28

tavit ohanian's avatar
tavit ohanian committed
29 30 31 32 33
		// 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)
Juan Batiz-Benet's avatar
docs  
Juan Batiz-Benet committed
34 35
*/
package multiaddr