mirror of
https://github.com/bestnite/sub2sing-box.git
synced 2025-10-28 09:33:57 +00:00
整理代码
This commit is contained in:
23
parser/port.go
Normal file
23
parser/port.go
Normal file
@@ -0,0 +1,23 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user