by

Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
Dean Karn
@deankarn
(define “package main”) at the top
Omar Massad
@Massad
validator.go have package forms
But in main.go it's reading it
it's not reading it*
Dean Karn
@deankarn
oh so gin_validator.go and main are in different packages then, that’s why
Omar Massad
@Massad
ya
main.go and validator.go (custom)
Dean Karn
@deankarn
we defined “defaultValidator” starting with lowercase so it’s not exposed (public) to other pakages
Omar Massad
@Massad

forms /
form1.go
validator.go

main.go

aha
Dean Karn
@deankarn
ok so you just have to change “defaultValidator” to “DefaultValidator” in your validator.go
Omar Massad
@Massad
ok just as ec
sec*
It's working now! binding.Validator = &forms.DefaultValidator{}
You are amazing, thank you!
Dean Karn
@deankarn
no problems :) glad you got it working
Omar Massad
@Massad
A silly question, doing that move or similar moves in the future would effect the performance in a noticeable way?
The overriding thing
Dean Karn
@deankarn
no not at all
Omar Massad
@Massad
Cool, thank you again :+1:
Dean Karn
@deankarn
gin used StructValidator as an interface to make it’s code pluggable and overriding does not effect performance at all
Omar Massad
@Massad
aha i see
Dean Karn
@deankarn
gin is a fantastic framework, if you ever wanted to start with something a little more low level and build your own framework you can take a look at my router https://github.com/go-playground/lars
Omar Massad
@Massad
I would to do that, since i'm still learning and developing using Gin
Would love*
Dean Karn
@deankarn
well again, glad I could help :) have a great day
Omar Massad
@Massad
Thank you again for your time and have a great day too :smile:
Andrius Solopovas
@asolopovas
Hi everyone.
Dean Karn
@deankarn
hello @asolopovas
muei
@muei
This message was deleted
type Cost struct {
  Unit string
  Fee float64
}

type Payment struct {
  Apple Cost // validate Apple.Fee gt=0
  Water Cost // no need validate
}
Is there some one can help me, how to define the tag that one need validate, the other not need
Dean Karn
@deankarn
type Pament struct {
Apple Cost // validate Apple.Fee gt=0
Water Cost // no need validate
}
Oops sorry didn't mean to send last message, tag should be validate:"gt=0"
muei
@muei
what do you mean?
Dean Karn
@deankarn
and for the Water field validate:"-"
muei
@muei
I want Apple.Cost.Fee great then zero
Dean Karn
@deankarn
the - tells validator to ignore field and the gt=0 should go on the Fee field, I'd write a full example but answering on my phone
muei
@muei
I know the rule. But I don't know how to differentia Apple.Fee and Water.Fee
type Cost struct {
  Unit string
  Fee float64  `validate:"gt=0"`
}

type Payment struct {
  Apple Cost  `validate:"required"`// validate Apple.Fee gt=0
  Water Cost `validate:"-"`// no need validate
}
I tried like this , but it will check all by Cost's define
Dean Karn
@deankarn
Yes , but when validating the Payment Struct if there is an error, the namespace of the error will be Payment.Apple.Fee differentiating itself from just the Cost Struct
muei
@muei
The below, my example , that will not work what I wanted.
I want Apple.Cost.Fee great then zero, but Water.Cost.Fee not validate. So how to define the tag in Payment or Cost
Dean Karn
@deankarn
Oh I see so validation is still happening for Water.Cost.Fee?
muei
@muei
I'm sorry I tried my old testing, It's OK now. @joeybloggs Thank you very much.
Dean Karn
@deankarn
No problem glad I could help
muei
@muei
This message was deleted
muei
@muei
type Demo struct {
   Date time.Time `validate:"gtetoday"`
}

func RegisterGTEToday(validate *validator.Validate) {
    validate.RegisterValidation("gtetoday", gtetoday)
}
func gtetoday(fl validator.FieldLevel) bool {
       var t time.Time
       // todo parse fl.Field()...
      println("Comparison date")
       return time.Now().Before(t)
}

func main() {
   validate := validator.New()
   validators.RegisterGreatThanToday(validate)

tmp:=Demo{}
...
  err := validate.Struct(&tmp)
 ....
}
Can someone help me? Why not print Comparison date. How to config the timetype
Dean Karn
@deankarn
You mean it's not reaching the println code? and shouldn't it be fmt.Println("")
muei
@muei
yeah
Dean Karn
@deankarn
I don't know how this can compile with println() and not fmt.Println() but I'll take a look when I get to a computer
P.S. nice to see someone checking out v9