In a http handler is there a way to get the port of the server that received the request without using http.Hijacker
to get the TCP connection, if there isn't is there a way to hijack the connection but still use the provided http.ResponseWriter
Get the local address from the request context using http.LocalAddrContextKey.
a, ok := req.Context().Value(http.LocalAddrContextKey).(net.Addr)
if !ok {
// handle address not found
}
Get the TCP port from the address:
ta, ok := a.(*net.TCPAddr)
if !ok {
// handle unknown address type
}
port := ta.Port