mirror of
https://github.com/logos-messaging/go-multiaddr.git
synced 2026-01-04 05:53:05 +00:00
modularize multiaddr protocols
This commit is contained in:
parent
dd8f16c47c
commit
b185168cd2
14
protocols.go
14
protocols.go
@ -55,6 +55,20 @@ var Protocols = []Protocol{
|
||||
Protocol{P_IPFS, LengthPrefixedVarSize, "ipfs", CodeToVarint(P_IPFS)},
|
||||
}
|
||||
|
||||
func AddProtocol(p Protocol) error {
|
||||
for _, pt := range Protocols {
|
||||
if pt.Code == p.Code {
|
||||
return fmt.Errorf("protocol code %d already taken by %q", p.Code, pt.Name)
|
||||
}
|
||||
if pt.Name == p.Name {
|
||||
return fmt.Errorf("protocol by the name %q already exists", p.Name)
|
||||
}
|
||||
}
|
||||
|
||||
Protocols = append(Protocols, p)
|
||||
return nil
|
||||
}
|
||||
|
||||
// ProtocolWithName returns the Protocol description with given string name.
|
||||
func ProtocolWithName(s string) Protocol {
|
||||
for _, p := range Protocols {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user