News for hackers. Stuff that matters.
Re:Quick and Clean in Go by thebigshane on Wednesday August 01, 2012 @06:49PM (#4326198)
If you don't care about the error (because you're just going to let the task die anyway). Then in Go, wouldn't you just write...

  _ := http.ListenAndServe(":8080", nil)

?
Re:Quick and Clean in Go by drivebyacct2 on Wednesday August 01, 2012 @07:02PM (#4326246)
You get a syntax error, "no new variables on left side of :=".

You could do:

    _ = http.ListenAndServe(*port, nil)
But why would you? Just omit it entirely. The only time you need to explicitly ignore errors is in multiple returns.

consider: http://play.golang.org/p/o8vLQQmRvp

which would be fixed like: http://play.golang.org/p/DH0j1cwRqW

But yes, since ListenAndServe is normally used to block before main() returns, you could let it fail and terminate. (But you'd probably want to exit with a non-zero value, at least I would).