func (l *networkListener) Config(certInfo *cert.Info) {
	config := cert.ServerTLSConfig(certInfo, l.logger)
	l.mutex.Lock()
	defer l.mutex.Unlock()
	l.config = config
}
Config safely swaps the underlying TLS configuration.
package endpoints
import (
	"crypto/tls"
	"fmt"
	"net"
	"sync"
	"github.com/go-kit/kit/log"
	"github.com/go-kit/kit/log/level"
	"github.com/pkg/errors"
	"github.com/spoke-d/thermionic/internal/cert"
)
func networkCreateListener(address string, cert *cert.Info, logger log.Logger) net.Listener {
	listener, err := net.Listen("tcp", canonicalNetworkAddress(address))
	if err != nil {
		level.Error(logger).Log("msg", "Cannot listen on https socket, skipping...", "err", err)
		return nil
	}
	return networkTLSListener(listener, cert, logger)
}
func canonicalNetworkAddress(address string) string {
	_, _, err := net.SplitHostPort(address)
	if err != nil {
		ip := net.ParseIP(address)
		if ip != nil && ip.To4() == nil {
			address = fmt.Sprintf("[%s]:%s", address, DefaultPort)
		} else {
			address = fmt.Sprintf("%s:%s", address, DefaultPort)
		}
	}
	return address
}
type networkListener struct {
	net.Listener
	mutex  sync.RWMutex
	config *tls.Config
	logger log.Logger
}
func networkTLSListener(inner net.Listener, cert *cert.Info, logger log.Logger) *networkListener {
	listener := &networkListener{
		Listener: inner,
		logger:   logger,
	}
	listener.Config(cert)
	return listener
}
func (l *networkListener) Accept() (net.Conn, error) {
	c, err := l.Listener.Accept()
	if err != nil {
		return nil, errors.WithStack(err)
	}
	l.mutex.RLock()
	defer l.mutex.RUnlock()
	config := l.config
	return tls.Server(c, config), nil
}