https://github.com/multiformats/go-multiaddr-fmt
A declarative validator for multiaddrs.
https://github.com/multiformats/go-multiaddr-fmt
Last synced: 4 months ago
JSON representation
A declarative validator for multiaddrs.
- Host: GitHub
- URL: https://github.com/multiformats/go-multiaddr-fmt
- Owner: multiformats
- License: mit
- Created: 2019-02-27T12:27:16.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2025-03-29T08:32:30.000Z (about 1 year ago)
- Last Synced: 2025-05-19T18:06:20.099Z (about 1 year ago)
- Language: Go
- Homepage:
- Size: 70.3 KB
- Stars: 5
- Watchers: 13
- Forks: 7
- Open Issues: 8
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# multiaddr format
A validation checker for multiaddrs. Some basic validators for common address
types are provided, but creating your own combinations is easy.
Usage:
```go
a, _ := ma.NewMultiaddr("/ip4/5.2.67.3/tcp/1708")
TCP.Matches(a) // returns true
```
Making your own validators is easy, for example, the `Reliable` multiaddr is
defined as follows:
```go
// Define IP as either ipv4 or ipv6
var IP = Or(Base(ma.P_IP4), Base(ma.P_IP6))
// Define TCP as 'tcp' on top of either ipv4 or ipv6
var TCP = And(IP, Base(ma.P_TCP))
// Define UDP as 'udp' on top of either ipv4 or ipv6
var UDP = And(IP, Base(ma.P_UDP))
// Define UTP as 'utp' on top of udp (on top of ipv4 or ipv6)
var UTP = And(UDP, Base(ma.P_UTP))
// Now define a Reliable transport as either tcp or utp
var Reliable = Or(TCP, UTP)
// From here, we can easily define multiaddrs for protocols that can run on top
// of any 'reliable' transport (such as ipfs)
```
NOTE: the above patterns are already implemented in package