🎨 Modify some code

This commit is contained in:
2024-04-23 14:41:14 +08:00
parent acf547f173
commit 0456c8f802
7 changed files with 45 additions and 26 deletions

View File

@@ -1,6 +1,7 @@
package parser
import (
"errors"
"strconv"
)
@@ -8,16 +9,10 @@ func ParsePort(portStr string) (uint16, error) {
port, err := strconv.Atoi(portStr)
if err != nil {
return 0, &ParseError{
Type: ErrInvalidPort,
Message: portStr,
}
return 0, err
}
if port < 1 || port > 65535 {
return 0, &ParseError{
Type: ErrInvalidPort,
Message: portStr,
}
return 0, errors.New("invaild port range")
}
return uint16(port), nil
}