Skip to content

Commit

Permalink
add example for package gvalid (#2767)
Browse files Browse the repository at this point in the history
  • Loading branch information
gqcn authored Jul 14, 2023
1 parent a2fec50 commit 5e231f3
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions util/gvalid/gvalid_z_example_feature_rule_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,34 @@ func ExampleRule_Email() {
// The MailAddr4 value `gf#goframe.org` is not a valid email address
}

func ExampleRule_Enums() {
type Status string
const (
StatusRunning Status = "Running"
StatusOffline Status = "Offline"
)
type BizReq struct {
Id int `v:"required"`
Name string `v:"required"`
Status Status `v:"enums"`
}

var (
ctx = context.Background()
req = BizReq{
Id: 1,
Name: "john",
Status: Status("Pending"),
}
)
if err := g.Validator().Data(req).Run(ctx); err != nil {
fmt.Print(gstr.Join(err.Strings(), "\n"))
}

// May Output:
// The Status value `Pending` should be in enums of: ["Running","Offline"]
}

func ExampleRule_Phone() {
type BizReq struct {
PhoneNumber1 string `v:"phone"`
Expand Down

0 comments on commit 5e231f3

Please sign in to comment.