mirror of
https://github.com/nitezs/sub2sing-box.git
synced 2024-12-23 20:14:42 -05:00
24 lines
363 B
Go
24 lines
363 B
Go
|
package parser
|
||
|
|
||
|
import (
|
||
|
"strconv"
|
||
|
)
|
||
|
|
||
|
func ParsePort(portStr string) (uint16, 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 uint16(port), nil
|
||
|
}
|