Advertisement
Guest User

Untitled

a guest
Mar 18th, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.53 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4. "fmt"
  5.  
  6. "github.com/asaskevich/govalidator"
  7. uuid "github.com/satori/go.uuid"
  8. )
  9.  
  10. type Student struct {
  11. ID uuid.UUID ` valid:"required"`
  12. }
  13.  
  14. func main() {
  15.  
  16. uid, _ := uuid.FromString("738b4a92-868b-4fea-a4bb-00fdfb27f05a")
  17. student := Student{
  18. ID: uid,
  19. }
  20.  
  21. govalidator.SetFieldsRequiredByDefault(true)
  22. valid, err := govalidator.ValidateStruct(student)
  23. if !valid {
  24. fmt.Println(err.Error())
  25. }
  26.  
  27. /*
  28. test case
  29. fb11dbae-76c3-4a2b-baf7-92aeb29374fd : valid
  30. 738b4a92-868b-4fea-a4bb-00fdfb27f05a : invalid
  31. */
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement