3 ms·
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(":
by thebigshane 14y ago
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)
?
- drivebyacct2 14y agoYou 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 http://play.golang.org/p/o8vLQQmRvp which would be fixed like: http://play.golang.org/p/DH0j1cwRqW 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).