Skip to content

Conversation

rtomadpg
Copy link

Fixes Or Enhances

Here is a little PR to say thank you, for providing your framework.

Let's add a validator for IPv4 bind addresses.

Examples of valid input:

  • :9000 for port 9000 on any IP address
  • 1.2.3.4:7777 for port 7777 on specific IP address

My use case: I need this validator for an application's config including IP based socket listener addresses, like: :9999 or 127.0.0.1:9999

Make sure that you've checked the boxes below before you submit PR:

  • Tests exist or have been written that cover this particular change.

@go-playground/validator-maintainers

@rtomadpg rtomadpg requested a review from a team as a code owner June 17, 2024 09:35
supporting older Golang versions by using net.ParseIP, not netip.ParseAddr
@rtomadpg rtomadpg force-pushed the feat-add-ipv4port branch from 9597b0f to e022a95 Compare June 17, 2024 09:52
@coveralls
Copy link

Coverage Status

coverage: 74.316% (+0.03%) from 74.291%
when pulling e022a95 on rtomadpg:feat-add-ipv4port
into a947377 on go-playground:master.

Co-authored-by: nodivbyzero <nodivbyzero@gmail.com>
return false
}
// Validate port range (1-65535).
if portNum, err := strconv.ParseUInt(port, 10, 32,); err != nil || portNum < 1 || portNum > 65535 {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if portNum, err := strconv.ParseUInt(port, 10, 32,); err != nil || portNum < 1 || portNum > 65535 {
if portNum, err := strconv.ParseUint(port, 10, 32); err != nil || portNum < 1 || portNum > 65535 {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

4 participants