2024-04-23 13:36:33 +08:00
|
|
|
package parser
|
|
|
|
|
|
|
|
import (
|
2024-04-23 14:39:16 +08:00
|
|
|
"errors"
|
2024-04-23 13:36:33 +08:00
|
|
|
"strconv"
|
|
|
|
)
|
|
|
|
|
|
|
|
func ParsePort(portStr string) (int, error) {
|
|
|
|
port, err := strconv.Atoi(portStr)
|
|
|
|
|
|
|
|
if err != nil {
|
2024-04-23 14:39:16 +08:00
|
|
|
return 0, err
|
2024-04-23 13:36:33 +08:00
|
|
|
}
|
|
|
|
if port < 1 || port > 65535 {
|
2024-04-23 14:39:16 +08:00
|
|
|
return 0, errors.New("invaild port range")
|
2024-04-23 13:36:33 +08:00
|
|
|
}
|
|
|
|
return port, nil
|
|
|
|
}
|