aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authoraimuz <mr.imuz@gmail.com>2024-05-17 06:13:32 +0000
committerGopher Robot <gobot@golang.org>2024-05-18 03:13:26 +0000
commit1667dbd7be0da5e75a25f14c339c859ed2190b43 (patch)
tree9f4fe9be84c35b24c0b3877d6555379ce5bba8c4 /src
parent105ac94486f243fc478c3a146d836302a95cdbbc (diff)
downloadgo-1667dbd7be0da5e75a25f14c339c859ed2190b43.tar.xz
net: use stringslite package for string operations
- Replace manual string suffix removal with stringslite.TrimSuffix in conf.go - Use stringslite.Cut for string splitting in ParseCIDR function in ip.go - Add stringslite import in ip.go This change simplifies string operations and improves code readability. Change-Id: I02c238d0bc91e95789d8060e6ef4c7d4f6e3f0d9 GitHub-Last-Rev: aef5dc5011217abc95b2a2d7c1d991ca84060d59 GitHub-Pull-Request: golang/go#67461 Reviewed-on: https://go-review.googlesource.com/c/go/+/586157 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Auto-Submit: Ian Lance Taylor <iant@golang.org> Commit-Queue: Ian Lance Taylor <iant@golang.org> Reviewed-by: Damien Neil <dneil@google.com>
Diffstat (limited to 'src')
-rw-r--r--src/net/conf.go4
-rw-r--r--src/net/ip.go6
2 files changed, 4 insertions, 6 deletions
diff --git a/src/net/conf.go b/src/net/conf.go
index 7499d49045..358f5434c4 100644
--- a/src/net/conf.go
+++ b/src/net/conf.go
@@ -336,9 +336,7 @@ func (c *conf) lookupOrder(r *Resolver, hostname string) (ret hostLookupOrder, d
}
// Canonicalize the hostname by removing any trailing dot.
- if stringslite.HasSuffix(hostname, ".") {
- hostname = hostname[:len(hostname)-1]
- }
+ hostname = stringslite.TrimSuffix(hostname, ".")
nss := getSystemNSS()
srcs := nss.sources["hosts"]
diff --git a/src/net/ip.go b/src/net/ip.go
index 6083dd8bf9..49124d95e7 100644
--- a/src/net/ip.go
+++ b/src/net/ip.go
@@ -15,6 +15,7 @@ package net
import (
"internal/bytealg"
"internal/itoa"
+ "internal/stringslite"
"net/netip"
)
@@ -515,11 +516,10 @@ func parseIP(s string) ([16]byte, bool) {
// For example, ParseCIDR("192.0.2.1/24") returns the IP address
// 192.0.2.1 and the network 192.0.2.0/24.
func ParseCIDR(s string) (IP, *IPNet, error) {
- i := bytealg.IndexByteString(s, '/')
- if i < 0 {
+ addr, mask, found := stringslite.Cut(s, "/")
+ if !found {
return nil, nil, &ParseError{Type: "CIDR address", Text: s}
}
- addr, mask := s[:i], s[i+1:]
ipAddr, err := netip.ParseAddr(addr)
if err != nil || ipAddr.Zone() != "" {