Skip to content

When the validation field does not exist #1399

Open
@how2j-coder

Description

@how2j-coder

struct

type Request struct {
	Name  string `json:"name" validate:"optional_not_empty"`
	Email string `json:"email"`
}

How Customize one optional_not_empty to achieve the following results?

cases

testCases := []Request{
	{ Email: ""},         // The Name field is not inpassed, and the verification is passed
	{Name: "John", Email: ""},     // Name is passed in and the verification passes
        {Name: "", Email: ""},     // Name is passed in, but the value is blank and the verification fails
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions