go-playground / validator

:100:Go Struct and Field validation, including Cross Field, Cross Struct, Map, Slice and Array diving
MIT License
16.64k stars 1.32k forks source link

Add support for numeric ports #1216

Open jtuchel opened 8 months ago

jtuchel commented 8 months ago

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

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 commented 3 months ago

very good proposal, hope to merge as soon as possible