mirror of
https://github.com/nitezs/sub2clash.git
synced 2024-12-23 22:04:41 -05:00
24 lines
352 B
Go
24 lines
352 B
Go
package parser
|
|
|
|
import (
|
|
"strconv"
|
|
)
|
|
|
|
func ParsePort(portStr string) (int, error) {
|
|
port, err := strconv.Atoi(portStr)
|
|
|
|
if err != nil {
|
|
return 0, &ParseError{
|
|
Type: ErrInvalidPort,
|
|
Message: portStr,
|
|
}
|
|
}
|
|
if port < 1 || port > 65535 {
|
|
return 0, &ParseError{
|
|
Type: ErrInvalidPort,
|
|
Message: portStr,
|
|
}
|
|
}
|
|
return port, nil
|
|
}
|