go-multiaddr
![codecov.io](https://img.shields.io/codecov/c/github/multiformats/go-multiaddr.svg?style=flat-square&branch=master)
multiaddr implementation in go
Multiaddr is a standard way to represent addresses that:
- Support any standard network protocols.
- Self-describe (include protocols).
- Have a binary packed format.
- Have a nice string representation.
- Encapsulate well.
Table of Contents
Install
go get github.com/multiformats/go-multiaddr
Usage
Example
Simple
import ma "github.com/multiformats/go-multiaddr"
m1, err := ma.NewMultiaddr("/ip4/127.0.0.1/udp/1234")
m2, err := ma.NewMultiaddrBytes(m1.Bytes())
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
m1.Protocols()
En/decapsulate
import ma "github.com/multiformats/go-multiaddr"
m, err := ma.NewMultiaddr("/ip4/127.0.0.1/udp/1234")
sctpMA, err := ma.NewMultiaddr("/sctp/5678")
m.Encapsulate(sctpMA)
udpMA, err := ma.NewMultiaddr("/udp/1234")
m.Decapsulate(udpMA)
Tunneling
Multiaddr allows expressing tunnels very nicely.
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)
Contribute
Contributions welcome. Please check out the issues.
Check out our contributing document for more information on how we work, and about contributing in general. Please be aware that all interactions related to multiformats are subject to the IPFS Code of Conduct.
Small note: If editing the README, please conform to the standard-readme specification.
License
MIT © 2014 Juan Batiz-Benet