Only accept HTTP connections from Localhost in Go?
<p>I have a simple HTTP Server standing up in Golang: </p>

<pre><code>h := http.NewServeMux()
h.Handle("/somepath", MyHandler)

s := &amp;http.Server{
    Addr:    "1234",
    Handler: h,
}   

s.ListenAndServe();
</code></pre>

<p>What is the best way to drop connections where the caller is not localhost?  Currently I'm considering inspecting the underlying connection information and ensuring that the IP Address is <code>127.0.0.1</code>, but this wastes a whole lot of resources (and runs through a whole bunch of Go code) before ultimately dropping the connection.  Ideally, I can instrument the Golang server to drop the initial TCP SYN packet based on IP Address, and not create a TCP connection at all (or reveal that this port is listening).</p>

<p>What's the cleanest path forward here?</p>