Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
Alkesh Ghorpade
@_alkesh26_twitter
i am expecting the request to fail throwing error data has 0 length, but my request is a success.
Forgot to mention i am using the gin library
Alkesh Ghorpade
@_alkesh26_twitter
sorry to bother you guys figured it out :)
Denys Yaroshenko
@freezlite
How to make eq operator case insensitive ?
Dean Karn
@deankarn
@freezlite Just copy the current eq validation from the repo
And lowercase strings before the comparison and register your own custom validation
Denys Yaroshenko
@freezlite
OH my god, last message from me 4 oct
I need to validate field IF another field equal something
how this can be done ?
Dean Karn
@deankarn
Once the validation logic gets this complex, it’s best to creat a StructLevel validation for this kind of logic, it works hand in hand with the struct tag validation :) just check out the examples in the repo and if you ya e any question let me know
Shawn Smith
@shawnsmithdev
hello
goodbye :(
Emir Ribić
@ribice
Hi
Just curious, I'm implementing pagination.
I need limit and offset to be positive numbers, but not mandatory ones.
So they are min:0, mandatory false
or something like that
if I put min:0 only
it fails if I don't send the field
Emir Ribić
@ribice
i mean min:1
Dean Karn
@deankarn
@ribice have you tried omitempty,min=1?
Emir Ribić
@ribice
No, I did it manually at that time (e.g. < 1)
Dean Karn
@deankarn
If you use
The validation I mention, that should work for your case
Ryan King
@ryanking
how do i get FieldError Namespace() to take into account json tag names? some of the docs make it sound like that should be happening, but it doesn't seem to be working for me
Dean Karn
@deankarn
Have you registered a tagNameFunc? That's OST likely why it wouldn't
*most likely
Ryan King
@ryanking
@joeybloggs oh I thought it would pick up names from the json tags already?
Dean Karn
@deankarn
it used to in an older version, but defining your own allows for much more flexible parsing of names, even from tags other than JSON
Ryan King
@ryanking
ah ok that makes sense
emurmotol
@emurmotol
how to validate big ints?
Value *big.Int json:"value" binding:"required,min=1000000000000000" // does not work
Franklin Harding
@fharding1
Hello! I just created this PR to add excludesfield and containsfield baked-in validators: go-playground/validator#424.
Pomke
@pomke
Hiya, sorry if this is a bit of a newbie question, I have a struct:
type LoginProvider struct {
Email string json:"email"
Phone string json:"phone"
Password string json:"password"
}
I want to validate XOR email and Phone
ie: you must provide either Email or Phone, but not both
Dean Karn
@deankarn
@pomke Once getting that specific I recommend either creating your own custom validation or creations a struct level validation.
Pomke
@pomke
Ok thank you ^_^
Devi
@asldevi
Hi, how can one inject something from application in the custom validation functions ?
Dean Karn
@deankarn
@asldevi You can Register a validation function that accepts context.Context and then use one of the validation functions that accept it eg. validate.StructCtx, but that's if it's dynamic, if looking to embed static logic from the application see here for an example go-playground/validator#462
Devi
@asldevi
thanks @deankarn
Emir Ribić
@ribice
Is this still active
:D
Dean Karn
@deankarn
yes
PhamDuykhang
@PhamDuykhang
Which tag can use for validate a string, i want to validate wich to string "times" and "Money"
Dean Karn
@deankarn

Documentation can be found here with all tags https://godoc.org/gopkg.in/go-playground/validator.v9

At present there is no built in "Money" nor "times" validator due to different locales having to validate differently, but you can create your own validations :)