Code:
https://github.com/inconshreveable/go-vhost
It's a library that lets you implement custom name-based virtual-host like behavior for protocols that support it. You give it a connection and a protocol and it returns to you the hostname and a new connection object that works as if nothing had been read from the original connection.
An illustrative example:
conn, _ := l.Accept()
// reads out the ClientHello message and parses the hostname out of the SNI extension
newConn, err := vhost.TLS(conn)
// take different behaviors based on the hostname
switch newConn.Host() {
}
The intended audience is small, just people implementing their own servers/proxies. I needed it for more than one of my projects though so I split it out into a library in case anyone else could benefit.
Currently only HTTP and TLS are supported.