func NewNetAddressString(addr string) (*NetAddress, error) {
	host, portStr, err := net.SplitHostPort(addr)
	if err != nil {
		return nil, err
	}
	ip := net.ParseIP(host)
	if ip == nil {
		if len(host) > 0 {
			ips, err := net.LookupIP(host)
			if err != nil {
				return nil, err
			}
			ip = ips[0]
		}
	}
	port, err := strconv.ParseUint(portStr, 10, 16)
	if err != nil {
		return nil, err
	}
	na := NewNetAddressIPPort(ip, uint16(port))
	return na, nil
}
Also resolves the host if host is not an IP.
package p2p
import (
	"errors"
	"fmt"
	"net"
	"strconv"
	"time"
	"go.uber.org/zap"
	. "github.com/annchain/annchain/module/lib/go-common"
)
type NetAddress struct {
	IP   net.IP
	Port uint16
	str  string
}
func NewNetAddress(logger *zap.Logger, addr net.Addr) *NetAddress {
	tcpAddr, ok := addr.(*net.TCPAddr)
	if !ok {
		logger.Warn(`Only TCPAddrs are supported. If used for anything but testing,
			may result in undefined behaviour!`, zap.Stringer("addr", addr))
		return NewNetAddressIPPort(net.IP("0.0.0.0"), 0)
	}
	ip := tcpAddr.IP
	port := uint16(tcpAddr.Port)
	return NewNetAddressIPPort(ip, port)
}
func NewNetAddressStrings(addrs []string) ([]*NetAddress, error) {
	netAddrs := make([]*NetAddress, len(addrs))
	for i, addr := range addrs {
		netAddr, err := NewNetAddressString(addr)
		if err != nil {
			return nil, errors.New(fmt.Sprintf("Error in address %s: %v", addr, err))
		}
		netAddrs[i] = netAddr
	}
	return netAddrs, nil
}