Skip to content

Conversation

@samber
Copy link
Contributor

@samber samber commented Apr 20, 2020

  • Nil is valid when a pointer is nil
  • Empty is valid when non-nil pointers is empty (== valid when nil || empty)

Example:

type People struct { DeprecatedField *string Type string IDCard string } func (p People) Validate() error { return validation.ValidateStruct(&p, validation.Field(&p.DeprecatedField, validation.Nil), validation.Field(&p.IDCard, validation.When(a.Type != "citizen", validation.Empty)),	) } func main() { str := "hello world" p := People{ DeprecatedField: &str, Type: "foreigner", IDCard: "1234567890",	} err := p.Validate() }
@coveralls
Copy link

coveralls commented Apr 20, 2020

Coverage Status

Coverage remained the same at 100.0% when pulling bef11e1 on samber:feat-absent into f6ac6c4 on go-ozzo:master.

@qiangxue
Copy link
Member

Thank you for your contribution!

@qiangxue qiangxue merged commit c098b9a into go-ozzo:master Apr 26, 2020
ltns35 pushed a commit to ltns35/ozzo-validation that referenced this pull request Jun 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants