type connErrPair … type multiListener … var _ … // MultiListen returns net.Listener which can listen on and accept connections for // the given network on multiple addresses. Internally it uses stdlib to create // sub-listener and multiplexes connection requests using go-routines. // The network must be "tcp", "tcp4" or "tcp6". // It follows the semantics of net.Listen that primarily means: // 1. If the host is an unspecified/zero IP address with "tcp" network, MultiListen // listens on all available unicast and anycast IP addresses of the local system. // 2. Use "tcp4" or "tcp6" to exclusively listen on IPv4 or IPv6 family, respectively. // 3. The host can accept names (e.g, localhost) and it will create a listener for at // most one of the host's IP. func MultiListen(ctx context.Context, network string, addrs ...string) (net.Listener, error) { … } // multiListen implements MultiListen by consuming stdlib functions as dependency allowing // mocking for unit-testing. func multiListen( ctx context.Context, network string, addrs []string, listenFunc func(ctx context.Context, network, address string) (net.Listener, error), ) (net.Listener, error) { … } // Accept implements net.Listener. It waits for and returns a connection from // any of the sub-listener. func (ml *multiListener) Accept() (net.Conn, error) { … } // Close implements net.Listener. It will close all sub-listeners and wait for // the go-routines to exit. func (ml *multiListener) Close() error { … } // Addr is an implementation of the net.Listener interface. It always returns // the address of the first listener. Callers should use conn.LocalAddr() to // obtain the actual local address of the sub-listener. func (ml *multiListener) Addr() net.Addr { … } // Addrs is like Addr, but returns the address for all registered listeners. func (ml *multiListener) Addrs() []net.Addr { … }