Skip to content

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

Closed
@adonovan

Description

@adonovan

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions