Go's standard library handles WebSockets by hijacking the HTTP connection to bypass the HTTP protocol layer. Use the http.Hijacker interface on the ResponseWriter to take control of the underlying net.Conn and perform the WebSocket handshake manually.
if hijacker, ok := w.(http.Hijacker); ok {
conn, bufrw, err := hijacker.Hijack()
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
defer conn.Close()
// Perform WebSocket handshake on conn/bufrw here
}