Go: net: document where service names come from?

Created on 4 Apr 2019  路  5Comments  路  Source: golang/go

Found in net/http/server.go:

type Server struct {
    Addr    string  // TCP address to listen on, ":http" if empty

What is this ":http" exactly? Presumably an alias, but I can't find any concrete documentation to know what it resolves to.

https://github.com/golang/go/blob/964fe4b80ff7a9e5490f11de0e216ae34a019ebc/src/net/http/server.go#L2477

Documentation FrozenDueToAge NeedsFix Suggested help wanted

Most helpful comment

@bradfitz How about mention that service name is defined in RFC 6335, and assigned by IANA

For each OS:

  • *nix: /etc/services
  • Windows: %WINDIR%\system32\drivers\etc\services
  • Plan 9: /lib/ndb/{local,global}

Document each OS seems too much details.

All 5 comments

https://golang.org/pkg/net/#Listen references
https://golang.org/pkg/net/#Dial which says "The port must be a literal port number or a service name."

Perhaps we should mention that comes from /etc/services (or equivalent, depending on OS).

@bradfitz How about mention that service name is defined in RFC 6335, and assigned by IANA

For each OS:

  • *nix: /etc/services
  • Windows: %WINDIR%\system32\drivers\etc\services
  • Plan 9: /lib/ndb/{local,global}

Document each OS seems too much details.

Is there missing a description of the address format in general? -- Empty host or port, port "0", square brackets for ipv6 addresses, ... As a reader of the comment I would also be interested in what does using the service name effectively means -- will it be port 80 or a dynamically assigned port from the 80** range?

Can we do something like this?

type Server struct {

    // TCP address to listen on, ":http" (all IP addresses,
    // default http port) if empty
    // See package net for description of the address format
    Addr string

As this issue has been inactive for a while, I'll submit a PR following @luka-zitnik suggestion.

Change https://golang.org/cl/191557 mentions this issue: net/http: enhance documentation for Server.Addr

Was this page helpful?
0 / 5 - 0 ratings