-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparser.go
More file actions
30 lines (25 loc) · 618 Bytes
/
parser.go
File metadata and controls
30 lines (25 loc) · 618 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package main
import (
"fmt"
"net"
"strconv"
"strings"
)
func ParseConnectionDetails(connectionDetails string) (string, int, error) {
parts := strings.Split(connectionDetails, ":")
if len(parts) != 2 {
return "", 0, fmt.Errorf("invalid connection details format")
}
host := parts[0]
if host != "localhost" && net.ParseIP(host) == nil {
return "", 0, fmt.Errorf("invalid IP address")
}
port, err := strconv.Atoi(parts[1])
if err != nil {
return "", 0, fmt.Errorf("invalid port number")
}
if port < 1 || port > 65535 {
return "", 0, fmt.Errorf("port out of range")
}
return host, port, nil
}