[#31] network: Make the address a separate type

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2020-09-17 12:09:49 +03:00 committed by Alex Vanin
parent d6a4965841
commit 44def45ff4
2 changed files with 21 additions and 5 deletions

View file

@ -6,7 +6,22 @@ import (
// Address represents the NeoFS node
// network address.
//
// It is a type alias of
// github.com/multiformats/go-multiaddr.Multiaddr.
type Address = multiaddr.Multiaddr
type Address struct {
ma multiaddr.Multiaddr
}
func (a Address) String() string {
return a.ma.String()
}
// AddressFromString restores address from a string representation.
func AddressFromString(s string) (*Address, error) {
ma, err := multiaddr.NewMultiaddr(s)
if err != nil {
return nil, err
}
return &Address{
ma: ma,
}, nil
}

View file

@ -3,11 +3,12 @@ package network
import (
"net"
"github.com/multiformats/go-multiaddr"
manet "github.com/multiformats/go-multiaddr-net"
)
// Listen announces on the local network address.
func Listen(addr Address) (net.Listener, error) {
func Listen(addr multiaddr.Multiaddr) (net.Listener, error) {
mLis, err := manet.Listen(addr)
if err != nil {
return nil, err