aboutsummaryrefslogtreecommitdiffhomepage
path: root/listeners.go
diff options
context:
space:
mode:
authorWilczyƄskiT <[email protected]>2022-08-04 19:17:35 +0200
committerGitHub <[email protected]>2022-08-04 11:17:35 -0600
commit2642bd72b7ca35b8622824fdffced2aefe1aaf11 (patch)
tree3bc73bada610bfee6377eb58d89ca18b72236966 /listeners.go
parent17ae5acaba536e98cfa86ddcd6967801f1fa1bbe (diff)
downloadcaddy-2642bd72b7ca35b8622824fdffced2aefe1aaf11.tar.gz
caddy-2642bd72b7ca35b8622824fdffced2aefe1aaf11.zip
Replace strings.Index usages with strings.Cut (#4930)
Diffstat (limited to 'listeners.go')
-rw-r--r--listeners.go17
1 files changed, 9 insertions, 8 deletions
diff --git a/listeners.go b/listeners.go
index d9cfbf286..3a8d49dd8 100644
--- a/listeners.go
+++ b/listeners.go
@@ -468,15 +468,15 @@ func ParseNetworkAddress(addr string) (NetworkAddress, error) {
}
var start, end uint64
if port != "" {
- ports := strings.SplitN(port, "-", 2)
- if len(ports) == 1 {
- ports = append(ports, ports[0])
+ before, after, found := strings.Cut(port, "-")
+ if !found {
+ after = before
}
- start, err = strconv.ParseUint(ports[0], 10, 16)
+ start, err = strconv.ParseUint(before, 10, 16)
if err != nil {
return NetworkAddress{}, fmt.Errorf("invalid start port: %v", err)
}
- end, err = strconv.ParseUint(ports[1], 10, 16)
+ end, err = strconv.ParseUint(after, 10, 16)
if err != nil {
return NetworkAddress{}, fmt.Errorf("invalid end port: %v", err)
}
@@ -498,9 +498,10 @@ func ParseNetworkAddress(addr string) (NetworkAddress, error) {
// SplitNetworkAddress splits a into its network, host, and port components.
// Note that port may be a port range (:X-Y), or omitted for unix sockets.
func SplitNetworkAddress(a string) (network, host, port string, err error) {
- if idx := strings.Index(a, "/"); idx >= 0 {
- network = strings.ToLower(strings.TrimSpace(a[:idx]))
- a = a[idx+1:]
+ beforeSlash, afterSlash, slashFound := strings.Cut(a, "/")
+ if slashFound {
+ network = strings.ToLower(strings.TrimSpace(beforeSlash))
+ a = afterSlash
}
if isUnixNetwork(network) {
host = a