Thanks for the response. I'm fairly new to Go, so just to confirm my
conclusion:
If you started the http server using "http.ListenAndServe()" function,
it's not possible to programatically get at the internal connection/
socket stuff (I can't seem to find any accessors functions for the
internals).
So instead you have to create the listener yourself and bind/serve it
by hand, and then give it to the http.Serve function
listner, err := net.Listen("tcp", "
127.0.0.1:0")
if err != nil {
log.Fatal("Listen:", err)
}
err2 := http.Serve(listner, nil)
if err2 != nil {
log.Fatal("http.Serve:", err2)
}
At this point the socket has been bound, and you can get it's new
port:
fmt.Printf("%s", listner.Addr().String());
Or is there an easier way that I'm just not seeing?
Thanks,
-Lucas
On Jul 7, 3:24 pm, Kyle Lemons <
kev...@google.com> wrote:
> I meant LocalAddr() <
http://golang.org/pkg/net/#Conn>, sorry about that.
>
>
>
>
>
>
>
> On Thu, Jul 7, 2011 at 3:23 PM, Kyle Lemons <
kev...@google.com> wrote:
> > Have a look at net.Conn.Addr().(TCPAddr).Port<
http://golang.org/pkg/net/#TCPAddr>
>
> > ~K