Skip to main content

required

required is a directive executor who tags a field as required.

Definition

Name: "required"
Args: (no args)

required always works as an accompany with some other directives, it checks if the field were set by the former directives. When the field were not set by the former directives, an error ErrMissingField will occur.

Usage

type TokenInput struct {
Token string `in:"query=access_token;required"`
}
RequestOutput
GET /users?access_token=abc&page=1
&TokenInput{
Token: "abc",
}
GET /users?page=1
// error occurred
&InvalidFieldError{
Field: "access_token",
Source: "required",
Value: nil,
ErrorMessage: "missing required field",
}