1
0
mirror of https://github.com/nitezs/sub2sing-box.git synced 2024-12-23 14:04:41 -05:00
sub2sing-box/parser/port.go

19 lines
278 B
Go
Raw Normal View History

2024-03-22 04:10:15 -04:00
package parser
import (
2024-04-23 02:41:14 -04:00
"errors"
2024-03-22 04:10:15 -04:00
"strconv"
)
func ParsePort(portStr string) (uint16, error) {
port, err := strconv.Atoi(portStr)
if err != nil {
2024-04-23 02:41:14 -04:00
return 0, err
2024-03-22 04:10:15 -04:00
}
if port < 1 || port > 65535 {
2024-04-23 02:41:14 -04:00
return 0, errors.New("invaild port range")
2024-03-22 04:10:15 -04:00
}
return uint16(port), nil
}