net/netip: update godoc comments

Streamline the godoc comments across Addr, AddrPort and Prefix in terms
of wording and godoc links. Add more and correct godoc links.

Change-Id: Id806ddcfafc9a99af483a9a6c94c6288d1ee4939
Reviewed-on: https://go-review.googlesource.com/c/go/+/779640
Reviewed-by: Michael Pratt <mpratt@google.com>
Auto-Submit: Tobias Klauser <tobias.klauser@gmail.com>
LUCI-TryBot-Result: golang-scoped@luci-project-accounts.iam.gserviceaccount.com <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Sean Liao <sean@liao.dev>
Reviewed-by: Florian Lehner <lehner.florian86@gmail.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
This commit is contained in:
Tobias Klauser 2026-05-19 21:22:43 +02:00 committed by Gopher Robot
parent acced3df03
commit c0bd270406

View file

@ -97,7 +97,7 @@ func AddrFrom4(addr [4]byte) Addr {
// AddrFrom16 returns the IPv6 address given by the bytes in addr.
// An IPv4-mapped IPv6 address is left as an IPv6 address.
// (Use Unmap to convert them if needed.)
// (Use [Addr.Unmap] to convert them if needed.)
func AddrFrom16(addr [16]byte) Addr {
return Addr{
addr: uint128{
@ -957,13 +957,13 @@ func (ip Addr) StringExpanded() string {
return string(ret)
}
// AppendText implements the [encoding.TextAppender] interface,
// It is the same as [Addr.AppendTo].
// AppendText implements the [encoding.TextAppender] interface.
// The encoding is the same as returned by [Addr.AppendTo].
func (ip Addr) AppendText(b []byte) ([]byte, error) {
return ip.AppendTo(b), nil
}
// MarshalText implements the [encoding.TextMarshaler] interface,
// MarshalText implements the [encoding.TextMarshaler] interface.
// The encoding is the same as returned by [Addr.String], with one exception:
// If ip is the zero [Addr], the encoding is the empty string.
func (ip Addr) MarshalText() ([]byte, error) {
@ -985,7 +985,7 @@ func (ip Addr) MarshalText() ([]byte, error) {
return ip.AppendText(buf)
}
// UnmarshalText implements the encoding.TextUnmarshaler interface.
// UnmarshalText implements the [encoding.TextUnmarshaler] interface.
// The IP address is expected in a form accepted by [ParseAddr].
//
// If text is empty, UnmarshalText sets *ip to the zero [Addr] and
@ -1034,7 +1034,7 @@ func (ip Addr) MarshalBinary() ([]byte, error) {
}
// UnmarshalBinary implements the [encoding.BinaryUnmarshaler] interface.
// It expects data in the form generated by MarshalBinary.
// It expects data in the form generated by [Addr.MarshalBinary].
func (ip *Addr) UnmarshalBinary(b []byte) error {
n := len(b)
switch {
@ -1201,15 +1201,15 @@ func (p AddrPort) AppendTo(b []byte) []byte {
return b
}
// AppendText implements the [encoding.TextAppender] interface. The
// encoding is the same as returned by [AddrPort.AppendTo].
// AppendText implements the [encoding.TextAppender] interface.
// The encoding is the same as returned by [AddrPort.AppendTo].
func (p AddrPort) AppendText(b []byte) ([]byte, error) {
return p.AppendTo(b), nil
}
// MarshalText implements the [encoding.TextMarshaler] interface. The
// encoding is the same as returned by [AddrPort.String], with one exception: if
// p.Addr() is the zero [Addr], the encoding is the empty string.
// MarshalText implements the [encoding.TextMarshaler] interface.
// The encoding is the same as returned by [AddrPort.String], with one exception:
// If p.Addr() is the zero [Addr], the encoding is the empty string.
func (p AddrPort) MarshalText() ([]byte, error) {
buf := []byte{}
switch p.ip.z {
@ -1224,9 +1224,9 @@ func (p AddrPort) MarshalText() ([]byte, error) {
return p.AppendText(buf)
}
// UnmarshalText implements the encoding.TextUnmarshaler
// interface. The [AddrPort] is expected in a form
// generated by [AddrPort.MarshalText] or accepted by [ParseAddrPort].
// UnmarshalText implements the [encoding.TextUnmarshaler] interface.
// The [AddrPort] is expected in a form generated by [AddrPort.MarshalText] or
// accepted by [ParseAddrPort].
func (p *AddrPort) UnmarshalText(text []byte) error {
if len(text) == 0 {
*p = AddrPort{}
@ -1512,9 +1512,9 @@ func (p Prefix) AppendText(b []byte) ([]byte, error) {
return p.AppendTo(b), nil
}
// MarshalText implements the [encoding.TextMarshaler] interface,
// MarshalText implements the [encoding.TextMarshaler] interface.
// The encoding is the same as returned by [Prefix.String], with one exception:
// If p is the zero value, the encoding is the empty string.
// If p is the zero [Prefix], the encoding is the empty string.
func (p Prefix) MarshalText() ([]byte, error) {
buf := []byte{}
switch p.ip.z {
@ -1529,7 +1529,7 @@ func (p Prefix) MarshalText() ([]byte, error) {
return p.AppendText(buf)
}
// UnmarshalText implements the encoding.TextUnmarshaler interface.
// UnmarshalText implements the [encoding.TextUnmarshaler] interface.
// The IP address is expected in a form accepted by [ParsePrefix]
// or generated by [Prefix.MarshalText].
func (p *Prefix) UnmarshalText(text []byte) error {
@ -1542,7 +1542,7 @@ func (p *Prefix) UnmarshalText(text []byte) error {
return err
}
// AppendBinary implements the [encoding.AppendMarshaler] interface.
// AppendBinary implements the [encoding.BinaryAppender] interface.
// It returns [Addr.AppendBinary] with an additional byte appended
// containing the prefix bits.
func (p Prefix) AppendBinary(b []byte) ([]byte, error) {