I've never seriously read golang code in my life before and I'm so deeply confused right now

I'm literally *one stack frame deep* and I'm seeing code that makes me want to scream

no sensible language would allow this to work even when SERVER_PORT isn't set:

port := os.Getenv("SERVER_PORT")
lis, err := net.Listen("tcp", "localhost:"+port)

> If the port in the address parameter is empty or "0", as in "" or "[::1]:0", a port number is automatically chosen. The Addr method of Listener can be used to discover the chosen port.



@iliana@cybre.space For bonus points, did you know that the `Addr` may not actually be what it's listening on?

That is to say, the following code can panic in some cases:

conn, err := net.Listen("tcp", ":8080")
if err != nil {
log.Fatal("couldn't listen")
_, err = net.Dial("tcp", conn.Addr().String())
if err != nil {
panic("this does happen in some cases")

For anyone curious about the details, it's basically "ipv6" github.com/moby/moby/issues/33

In go's defence, the behaviour was fixed in go1.9, so it probably can't panic anymore (whoops, didn't realize that until I looked it up now) github.com/golang/go/issues/18

Sign in to participate in the conversation
Wobscale Social

Hello internet stranger!

Wobscale.Social is a mastodon instance run by Wobscale Technologies, LLC.

It's primarily meant as a small little piece of the fediverse for members of Wobscale Technologies and friends of the wob.

General registrations are closed, but if you want an account, give a shout over toot, email, or irc, and we'll see what we can do.