package
0.0.0-20180911130330-d3ccc4fb1d66
Repository: https://github.com/rglyons/kube-arangodb.git
Documentation: pkg.go.dev

# README

Struct level validations

Validations can also be registered at the struct level when field level validations don't make much sense. This can also be used to solve cross-field validation elegantly. Additionally, it can be combined with tag validations. Struct Level validations run after the structs tag validations.

Example requests

# Validation errors are generated for struct tags as well as at the struct level
$ curl -s -X POST http://localhost:8085/user \
	-H 'content-type: application/json' \
	-d '{}' | jq
{
  "error": "Key: 'User.Email' Error:Field validation for 'Email' failed on the 'required' tag\nKey: 'User.FirstName' Error:Field validation for 'FirstName' failed on the 'fnameorlname' tag\nKey: 'User.LastName' Error:Field validation for 'LastName' failed on the 'fnameorlname' tag",
  "message": "User validation failed!"
}

# Validation fails at the struct level because neither first name nor last name are present
$ curl -s -X POST http://localhost:8085/user \
    -H 'content-type: application/json' \
	-d '{"email": "[email protected]"}' | jq
{
  "error": "Key: 'User.FirstName' Error:Field validation for 'FirstName' failed on the 'fnameorlname' tag\nKey: 'User.LastName' Error:Field validation for 'LastName' failed on the 'fnameorlname' tag",
  "message": "User validation failed!"
}

# No validation errors when either first name or last name is present
$ curl -X POST http://localhost:8085/user \
    -H 'content-type: application/json' \
	-d '{"fname": "George", "email": "[email protected]"}'
{"message":"User validation successful."}

$ curl -X POST http://localhost:8085/user \
    -H 'content-type: application/json' \
	-d '{"lname": "Contanza", "email": "[email protected]"}'
{"message":"User validation successful."}

$ curl -X POST http://localhost:8085/user \
    -H 'content-type: application/json' \
	-d '{"fname": "George", "lname": "Costanza", "email": "[email protected]"}'
{"message":"User validation successful."}

Useful links

# Functions

UserStructLevelValidation contains custom struct level validations that don't always make sense at the field validation level.

# Structs

User contains user information.