Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
Walter Schulze
@awalterschulze
Relapse does not support cross field validation though, since this will require a memory allocation and then the expression looses speed. There are some hacks to implement cross field validation uses custom functions on the leafs.
Regarding the runtime reflection. Katydid also does runtime reflect in its reflect parser https://github.com/katydid/katydid/blob/master/parser/reflect/reflect.go . The parser is just very naive at this point, but could easily be improved. I was just too lazy to do it for this test, before more buy in.
So yes this should all be possible, but given the hacks required for error returns and cross field validation, it is less simple that I initially thought.
Dean Karn
@deankarn
I didn't even mention the alias, or validations and dive logic I suspect it would be a lot of work and in the end not convinced it would be that much faster after it's all added in.
but still interested in taking a deeper look
Oh and I assume this would work for individual variables as well and not just structs?
Justin Clift
@justinclift
As a mention for the individual variables front... the current error output from validator is not fantastic. It just returns '' as the value which error-ed.
justinclift @justinclift has been meaning to look into that more, but well... it hasn't happened yet
Dean Karn
@deankarn
@justinclift ya looked into it when creating and there's just no way, that I have found, to get the variables name using reflection...only other thing that could be done is add another parameter for the name of the field, but that's not ideal either and doesn't work with dynamic variables. If you come up with anything though please let me know, definitely love to get better output :)
Walter Schulze
@awalterschulze
alias is already supported in relapse. I don't understand what dive is doing, but relapse supports recursion very well. The reflect parser would need some minor work for individual values, but the relapse logic will be fine with it.
Justin Clift
@justinclift
@joeybloggs No worries. :)
Alkesh Ghorpade
@_alkesh26_twitter

@all Guys u have this below struct

type PropertyMessage struct {
    id            string                   `form:"id" json:"id" binding:"required"`
    data         []map[string]interface{} `form:"data" json:"data" binding:"required" validate:"gt=0"`
}

Seems like gt is not working when my POST request payload is

{
     id: "abc",
     data: []
}
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.