net/netip: use const for max address length

Makes it consistent with other code in net/netip, also constants
are visible through LSP hover, which makes it easier to see the size.

Change-Id: I3d02c860ac3c61cc037eaca5418297f78698c3f8
GitHub-Last-Rev: 785a8d58c3
GitHub-Pull-Request: golang/go#69468
Reviewed-on: https://go-review.googlesource.com/c/go/+/613356
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
This commit is contained in:
Mateusz Poliwczak 2024-09-14 10:09:58 +00:00 committed by Gopher Robot
parent b28b263a91
commit d682a9dfbe

View File

@ -974,16 +974,16 @@ func (ip Addr) MarshalText() ([]byte, error) {
case z0:
return []byte(""), nil
case z4:
max := len("255.255.255.255")
const max = len("255.255.255.255")
b := make([]byte, 0, max)
return ip.appendTo4(b), nil
default:
if ip.Is4In6() {
max := len("::ffff:255.255.255.255%enp5s0")
const max = len("::ffff:255.255.255.255%enp5s0")
b := make([]byte, 0, max)
return ip.appendTo4In6(b), nil
}
max := len("ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff%enp5s0")
const max = len("ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff%enp5s0")
b := make([]byte, 0, max)
return ip.appendTo6(b), nil
}