From 191ad2043606481d5291db6a1ac2eddbe0e3a451 Mon Sep 17 00:00:00 2001 From: huangqian Date: Sun, 31 Oct 2021 23:16:54 +0800 Subject: [PATCH] Complete the following verification rule example method 1. date --- util/gvalid/gvalid_z_example_test.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/util/gvalid/gvalid_z_example_test.go b/util/gvalid/gvalid_z_example_test.go index aab2c8644..95dee5403 100644 --- a/util/gvalid/gvalid_z_example_test.go +++ b/util/gvalid/gvalid_z_example_test.go @@ -527,3 +527,28 @@ func ExampleValidator_NotIn() { // Output: // The InvalidIndex value is not in acceptable range } + +func ExampleValidator_Date() { + type BizReq struct { + Date1 string `v:"date"` + Date2 string `v:"date"` + Date3 string `v:"date"` + Date4 string `v:"date"` + } + + var ( + ctx = context.Background() + req = BizReq{ + Date1: "2021-10-31", + Date2: "2021.10.31", + Date3: "2021 10 31", + Date4: "31/10/2021", + } + ) + if err := g.Validator().CheckStruct(ctx, req); err != nil { + fmt.Print(err) + } + + // Output: + // The Date3 value is not a valid date; The Date4 value is not a valid date +}