mirror of
https://github.com/caddyserver/caddy.git
synced 2026-05-13 09:06:41 +00:00
Replace strings.Index usages with strings.Cut (#4930)
This commit is contained in:
parent
17ae5acaba
commit
2642bd72b7
8 changed files with 32 additions and 33 deletions
17
listeners.go
17
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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue