1
0
mirror of https://github.com/nitezs/sub2clash.git synced 2024-12-23 20:24:42 -05:00
sub2clash/parser/port.go

24 lines
352 B
Go
Raw Normal View History

2024-04-23 01:36:33 -04:00
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
}