mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
internal/flags: validate port
Signed-off-by: jsvisa <delweng@gmail.com>
This commit is contained in:
parent
614804b33c
commit
b315c4a741
1 changed files with 10 additions and 0 deletions
|
|
@ -375,3 +375,13 @@ func eachName(f cli.Flag, fn func(string)) {
|
|||
fn(name)
|
||||
}
|
||||
}
|
||||
|
||||
// ValidatePort validates the port number is in the valid range.
|
||||
func ValidatePort(name string) func(*cli.Context, int) error {
|
||||
return func(ctx *cli.Context, port int) error {
|
||||
if port < 0 || port >= 65535 {
|
||||
return fmt.Errorf("Flag %s value %v out of range[0-65535]", name, port)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue