Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

net/http: ListenAndServe examples are inconsistent about checking err != nil #12229

Closed
adonovan opened this issue Aug 20, 2015 · 2 comments

Comments

Projects
None yet
4 participants
@adonovan
Copy link

commented Aug 20, 2015

The doc comment at http.ListenAndServe says:

    err := http.ListenAndServe(":12345", nil)
    if err != nil {
        log.Fatal("ListenAndServe: ", err)
    }

whereas other examples in the same package say:

    log.Fatal(http.ListenAndServe(":12345", nil))

These shorter forms, though pleasingly succinct, rely on the undocumented assumption that if ListenAndServe ever returns, it returns non-nil.

The examples should either always check for nil, or ListenAndServe should document the non-nil postcondition.

@bradfitz

This comment has been minimized.

Copy link
Member

commented Aug 20, 2015

We could also document that ListenAndServe ways returns non-nil if we don't already.

@gopherbot

This comment has been minimized.

Copy link

commented Aug 20, 2015

CL https://golang.org/cl/13780 mentions this issue.

@adg adg closed this in b733234 Aug 20, 2015

@mikioh mikioh changed the title http.ListenAndServe examples are inconsistent about checking err != nil net/http: ListenAndServe examples are inconsistent about checking err != nil Aug 21, 2015

@mikioh mikioh added this to the Go1.6 milestone Aug 21, 2015

@golang golang locked and limited conversation to collaborators Aug 22, 2016

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.