Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for numeric ports #1216

Closed
2 tasks done
jtuchel opened this issue Jan 16, 2024 · 1 comment
Closed
2 tasks done

Add support for numeric ports #1216

jtuchel opened this issue Jan 16, 2024 · 1 comment

Comments

@jtuchel
Copy link

jtuchel commented Jan 16, 2024

  • I have looked at the documentation here first?
  • I have looked at the examples provided that may showcase my question here?

Package version eg. v9, v10:

v10

Issue, Question or Enhancement:

Please add support for numeric ports, e.g. a port of type uint. For now we have two options

  • use hostname_port and pass in a string, e.g. ":8080"
  • use a custom validation, e.g. validate:"gte=1,lte=65535"

Code sample, to showcase or reproduce:

The solution would be very similiar to this implementation

https://github.com/go-playground/validator/blob/master/baked_in.go#L2675

The keyword could be port, the implementation could be

func isPort(fl FieldLevel) bool {
	val := fl.Field().Uint()
	
	return val >= 1 && val <= 65535
}
@zandwang
Copy link

zandwang commented Jul 5, 2024

very good proposal, hope to merge as soon as possible

deankarn pushed a commit that referenced this issue Nov 16, 2024
## Fixes Or Enhances
This PR adds a new validation for numeric ports.
Connected to: #1216 

```
	type Host struct {
		Port uint32 `validate:"port"`
	}

```
**Make sure that you've checked the boxes below before you submit PR:**
- [x] Tests exist or have been written that cover this particular
change.

@go-playground/validator-maintainers
KimNorgaard pushed a commit to KimNorgaard/validator that referenced this issue Feb 25, 2025
## Fixes Or Enhances
This PR adds a new validation for numeric ports.
Connected to: go-playground#1216 

```
	type Host struct {
		Port uint32 `validate:"port"`
	}

```
**Make sure that you've checked the boxes below before you submit PR:**
- [x] Tests exist or have been written that cover this particular
change.

@go-playground/validator-maintainers
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants