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

19 lines
267 B
Go
Raw Normal View History

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